php check name 1

php check name

//You should use a regex filter with preg_match who returns 1 or 0

// this filter works for most of cases

/* use this regex */ preg_match("/^[a-z ,.'-]+$/i", your_string);

Here is what the above code is Doing:
1. The first part of the regex, ^[a-z ,.’-]+$ , is the actual filter.
2. The ^ means “start of the string”.
3. The $ means “end of the string”.
4. The + means “one or more of the previous thing”. In this case, the previous thing is a character class, which just means “any one of these”.
5. The character class [a-z ,.’-] means “any letter, any comma, any space, any apostrophe, any hyphen”.
6. The i at the end makes it case-insensitive.
7. The preg_match function is a regular expression function that returns 1 if the string matches the regex, and 0 if it doesn’t.

Similar Posts