Home > database >  Manipulate Regex to ignore the space and disallow numbers and special characters
Manipulate Regex to ignore the space and disallow numbers and special characters

Time:07-18

I have a working regex pattern to validate some name

/[ `!@#$%^&*()_ \-=\[\]{};':"\\|,.<>\/?~]/

it validates a full name

so I have to put a space in the middle of the word, means

"Ahmed Mohsen" > valid

"Ahmed" > not valid

I want to ignore the space, to make "Ahmed" valid

also, to disallow the numbers/special characters from the name

Note

the idea of determining characters from a to Z and so on, is a bad idea

because some users may write their names in Arabic (Arabic characters)

CodePudding user response:

As Wiktor Stribiżew mentioned in the comment, this can be achieved using:

/^(?:\p{L}\p{M}*) (?:\s(?:\p{L}\p{M}*) )*$/u

Please mark a correct answer so the question can be categorized appropriately.

  • Related