When any user creates or edits the company name, I want to make sure it contains only these characters:
- alphanumeric (A-Z, a-z, 0-9)
- , . ? ! @ & # ' ~ * _ - ; + and space
How to enforce this with a regular expression??
When any user creates or edits the company name, I want to make sure it contains only these characters:
How to enforce this with a regular expression??
$regEx = '/[^A-Za-z0-9,.?@&!#\'~* _-;+]/'
The key is to use a ^ after [ This negates the character list. Therefore any character that does not meet your criterias will be found.
You can use that for example like that
if (preg_match($regEx, $input)) {
throw new Exception('invalid character');
}