Advertisement
Help Keep Boards Alive. Support us by going ad free today. See here: https://subscriptions.boards.ie/.
If we do not hit our goal we will be forced to close the site.

Current status: https://keepboardsalive.com/

Annual subs are best for most impact. If you are still undecided on going Ad Free - you can also donate using the Paypal Donate option. All contribution helps. Thank you.
https://www.boards.ie/group/1878-subscribers-forum

Private Group for paid up members of Boards.ie. Join the club.

regex and internationalisation

  • 29-06-2012 09:33PM
    #1
    Registered Users, Registered Users 2 Posts: 860 ✭✭✭


    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, Registered Users 2 Posts: 2,062 ✭✭✭Colonel Panic


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


  • Registered Users, Registered Users 2 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, Registered Users 2 Posts: 1,110 ✭✭✭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