Advertisement
If you have a new account but are having problems posting or verifying your account, please email us on hello@boards.ie for help. Thanks :)
Hello all! Please ensure that you are posting a new thread or question in the appropriate forum. The Feedback forum is overwhelmed with questions that are having to be moved elsewhere. If you need help to verify your account contact hello@boards.ie

regex and internationalisation

Options
  • 29-06-2012 9:33pm
    #1
    Registered Users Posts: 859 ✭✭✭


    I'm validating user input on the browser to exclude special chars like !"£$%^&* using a regex something like [a-zA-Z0-9 ]

    The regex is doing what I want, my question is about internationalisation, (which is being done later, (I know))

    Will I have to adjust my regex per locale and hence should it itself be an externalisable string so that it is easier to do?

    Tks,
    Owen.


Comments

  • Registered Users Posts: 2,019 ✭✭✭Colonel Panic


    Best to plan ahead and have it possible to localise! Especially if it's being done later.


  • Registered Users Posts: 1,127 ✭✭✭smcelhinney


    In this instance what I would do is externalise in a properties file or locale bundle (Java speak).

    Eg.

    regex_en.properties might contain
    valid_string_regex=/[A-Za-z0-9 ]+/

    and regex_fr.properties might contain
    valid_string_regex=/[A-Za-z0-9éáí ]+/ (..etc)

    HTH
    Stephen


  • Registered Users Posts: 1,109 ✭✭✭Skrynesaver


    Many languages' regex library is based on Perl's (PCRE - Perl compatible regular expressions). Perl has locale dependent character class defined what you seem to want is \w (a word character). As it locale dependent i18n is automatic.

    Check the docs for your languages regex implementation.


Advertisement