0

I am quite confused on the issue of validating the fields (eg. business name, company name, address, etc.), because the site has localization feature. Currently, I am validating the fields using jQuery via regular expression, a snip of one of my regex:

var regex = /^[a-zA-Z0-9-,.\säöüÄÖÜ]{2,}$/;

This works fine when the site is in English language. However, I am not confident if this does work in German environment.

What I do to test my validation is by using Character Map on Windows. Say for example, I get ü from Character Map, paste it on the field. But the script says it is an invalid character. Whereas, if you look on the regex, I am considering such character as valid.

cwallenpoole
  • 79,954
  • 26
  • 128
  • 166
planet x
  • 1,599
  • 5
  • 26
  • 44
  • "I am not confident if this does work" - does that mean you haven't tried it? – JJJ Jan 16 '12 at 09:04
  • will this help you? http://stackoverflow.com/questions/7808390/jquery-validate-plugin-accept-only-german-letters – Vlad Jula-Nedelcu Jan 16 '12 at 09:22
  • i really do hope you not using javascript (jQuery) as you only validation method and you do the validation in PHP also. – Vlad Jula-Nedelcu Jan 16 '12 at 09:23
  • @VladNedelcu - Yeah, I only use jQuery for responsive, visually rich validation on my forms, it is backed up by server-side validation. – planet x Jan 16 '12 at 09:26
  • 4
    I really do hope you don't prevent people from entering names like Åsa, Ørjan, René etc just because they contain characters which are not "English or German". Attempting to validate my first name seems rather misdirected in the first place. What do you hope to accomplish with this? – tripleee Jan 16 '12 at 09:31
  • @tripleee - I edited my question, it was my bad to emphasize firstname and lastname as the fields to be validated. Based on your comment I am quite enlightened on what the approach should be. – planet x Jan 16 '12 at 09:48
  • Your regex requires 2 or more characters, so by that, a single `ü` is invalid because it is too short. Anyway, you probably want to allow the entire Latin repertoire without enumerating it, so perhaps you should rethink your approach. – tripleee Jan 16 '12 at 10:19
  • Tangentially see also http://stackoverflow.com/questions/4043307/why-this-regex-is-not-working-for-german-words – tripleee Jan 16 '12 at 10:27

1 Answers1

1

Most probably the technical problem is in the document’s character encoding. Make sure that your document is UTF-8 encoded and declared as such in HTTP headers or at least in a meta tag.

There are more difficult important problems though. Your regexp will reject the English name Brontë and the German name Strauß for example. And it will accept 42, which is hardly anyone’s first or last name.

What is the purpose of this checking? Can you expect that all the names will be English or German? According to European conventions, a person has the right to have his name spelled correctly in European countries, even if it happens to be in a language other than the majority language.

There’s not much checking of personal names that you can do without risk of rejecting someone’s real name in some accepted spelling. If you need to force names to some limited character repertoire or syntax, this needs to be made clear to users and performed server-side and, preferably, additionally as client-side pre-checking.

Jukka K. Korpela
  • 195,524
  • 37
  • 270
  • 390
  • Thanks for this informative answer. I edited my post, sorry my bad I am not particularly pertaining to firstname/lastname rather I am validating this for such business name/company name. Been applying this in a registration form. – planet x Jan 16 '12 at 09:38