Reputation: 2805
regexes?
to validate a name with only characters and spaces e.g.
Jon Skeet
to validate a number having digits and dashes anywhere e.g.
423-4324234-423
4233-412341324
Upvotes: 0
Views: 65
Reputation: 57179
A basic english name:
([a-zA-Z]+\s*)+
Numbers with dashes anywhere except for beginning and end:
\d[-\d]+\d
Numbers with dashes anywhere:
[-\d]+
Edit:
If you are looking for name inside of a sentence, such as
Hello, my name is John Doe.
You can try and capture names based on two or more capitalized words in a row.
([A-Z][A-Za-z]+\s*){2,}
Upvotes: 2
Reputation: 91528
To match a name in any language :
/^[\p{L} '-]+$/
That matches O'Connors Anne-Marie El Niño ...
to match your example digits:
/^[\d-]+$/
Upvotes: 1