0

I'm validating an email form and for the name input I wanna make sure the user didn't enter in punctuation, or numbers in the field. Just letters a-z upper-cased, and lower-cased.

This doesn't seem to work:

/(?![\._])\p{P}|[0-9]/g
Matthew
  • 2,158
  • 7
  • 30
  • 52
  • 4
    What do you have against `José O'Brien`? – Tim Pietzcker Jul 10 '13 at 05:46
  • What are you talking about? Like I wanna keep the accent marks, too. – Matthew Jul 10 '13 at 05:47
  • allow only A-Za-z instead to all this stuff. – jogesh_pi Jul 10 '13 at 05:47
  • 1
    `O'Brien` contains punctuation. Don't try to validate names: [Falsehoods programmers believe about names](http://www.kalzumeus.com/2010/06/17/falsehoods-programmers-believe-about-names/) – Tim Pietzcker Jul 10 '13 at 05:47
  • @TimPietzcker I'm 99% sure that he would be Jose.obrian@whatever.com or jobrian - not many systems allow non low-ASCII and accents in email addresses – mplungjan Jul 10 '13 at 05:49
  • @mplungjan: He's not validating an email field but a name field. Otherwise, he would probably want to allow the `@` and dots, don't you think? – Tim Pietzcker Jul 10 '13 at 05:50
  • This is the correct email one: http://stackoverflow.com/questions/46155/validate-email-address-in-javascript – Matthew Jul 10 '13 at 05:52
  • Oh dear. This is getting worse. Where did you find this nonsensical monster? This will reject many valid mail addresses and fail to reject many invalid ones. Why bother? Check if there is an `@` in the field, then try and send mail to it and catch any errors. – Tim Pietzcker Jul 10 '13 at 05:55
  • @TimPietzcker is this correct? http://stackoverflow.com/questions/46155/validate-email-address-in-javascript – Matthew Jul 10 '13 at 05:57
  • The second answer is: http://stackoverflow.com/a/815232/20670 – Tim Pietzcker Jul 10 '13 at 06:09

2 Answers2

1

You can just use

/[a-zA-Z]/g

To match a valid name

Hope this helps

Mangiucugna
  • 1,732
  • 1
  • 14
  • 23
0

Why not just match on /[a-zA-Z]/g then?

kalley
  • 18,072
  • 2
  • 39
  • 36