I'm trying to achieve validation for numeric input plus letter X or x. So far I have:
if(preg_match('/[^0-9xX]+$/', $data)) return 'error';
It correctly returns error for all cases EXCEPT a123. Have anyone idea why?
I'm trying to achieve validation for numeric input plus letter X or x. So far I have:
if(preg_match('/[^0-9xX]+$/', $data)) return 'error';
It correctly returns error for all cases EXCEPT a123. Have anyone idea why?
Use ^
at the start of regex to check if the complete string instead of sub-string.
if(preg_match('/^[0-9xX]+$/', $data))
return 'error';