0

I have the following if statement with a regular expression to check if an entry does not have lowercase and uppercase letters, however I need to include all foreign characters too like ü, ó etc. How could I include all these in my regex?

if (regsurname.match(/[^a-zA-Z]/g)) {
....

The main idea of it is to stop people from entering numbers or characters like *-/ in the surname field.

EDIT: I read that it can be done with this \p{L} but how would I include that in my regex exactly?

Thanks!

user1937021
  • 10,151
  • 22
  • 81
  • 143
  • 1
    Are you sure you want to include them [all](http://www.unicode.org/Public/6.3.0/ucd/UnicodeData-6.3.0d2.txt) ? – georg Apr 29 '13 at 16:11
  • yes all letters and all foreign letters – user1937021 Apr 29 '13 at 16:13
  • There are several thousands of them, you know. And unicode regexes like `\p{L}` don't work in javascript. – georg Apr 29 '13 at 16:15
  • 5
    Take 5 steps back. What are you trying to validate here to begin with and why? You want to validate *human names from any culture?* Then the best thing is not to. – deceze Apr 29 '13 at 16:16
  • I want people not to be able to write numbers or symbols like */-; etc. – user1937021 Apr 29 '13 at 16:23
  • 1
    In many cultures `-` is a valid character to indicate multiple last names. Similarly, `'` comes to mind for the Irish `O'-` last names. And that's only scratching the surface of possibilities. I'd also recommend not limiting the length of the field, or setting it to long enough - for example, for the multiple Spanish last names. – pilsetnieks Apr 29 '13 at 16:46
  • John Doe the 3rd won't be able to register then? Neither will Mrs. Schmidt-Schultz? – deceze Apr 29 '13 at 19:06

1 Answers1

0

Unicode regexp sequences like p{L} are supported in PHP but not JavaScript as far as I know.

Many surnames are hyphenated. It seems like you'd want to allow -.

Community
  • 1
  • 1
ryanve
  • 50,076
  • 30
  • 102
  • 137
  • nm i believe it is according to [MDN](https://developer.mozilla.org/en-US/docs/Web/HTML/Element/input/text#pattern) – oldboy Oct 07 '19 at 01:45