My regex works on validating first and last names. The acceptable forms are as follows:
- Jacob Wellman
- Wellman, Jacob
- Wellman, Jacob Wayne
- O’Shaughnessy, Jake L.
- John O’Shaughnessy-Smith
- Kim
The unacceptable forms are as follows:
- Timmy O’’Shaughnessy
- John O’Shaughnessy--Smith
- K3vin Malone
- alert(“Hello”)
- select * from users;
My current regex is as follows.
^[\w'\-,.][^0-9_!¡?÷?¿\\+=@#$%ˆ&*(){}|~<>;:[\]]{2,}$
It works properly for validating all of the names except for:
- Timmy O’’Shaughnessy
- John O’Shaughnessy--Smith
The reason for this is that the regex doesn't take into account consecutive identical special characters. How can I change my regex to take those into account?