#1
  1. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0

    Regular expression that works in mvc dont work in jQuery


    Hi

    I'm making an application in asp.net MVC and have following regular expression to validate input.

    ^[\p{L} ]+$

    In Mvc this works just as its supposed to, but when i try using it in client validation it wont work.

    Does anyone know why a regular expression that works fine in mvc dont work in jQuery, javascript?

    Below is the method used to validate input on client-side.

    var lettersonlyPattern = /^[\p{L} ]+$/

    lettersonlyPattern.test(val);
  2. #2
  3. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    Hi,

    what you need to understand is that regexes come in different flavors and have different features depending on the concrete language.

    JavaScript regexes don't have Unicode properties (\p{...}). You either have to make them available through a third-party library or replace them with a standard character class.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  4. #3
  5. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    Thanks, but i don't have time to read up on this subject, I just need to know how to make it work.

    It would be nice with a concrete example of how to handle the problem and a short explanation of why it works.
  6. #4
  7. --
    Devshed Expert (3500 - 3999 posts)

    Join Date
    Jul 2012
    Posts
    3,957
    Rep Power
    1046
    This is no "code for free" forum handing out solutions for you to copy and paste.

    I gave you a link to a library. On the bottom of the page, there are several examples explaining exactly what to do. If you don't even have time for that, I fear we have no time for you either.
    The 6 worst sins of security ē How to (properly) access a MySQL database with PHP

    Why canít I use certain words like "drop" as part of my Security Question answers?
    There are certain words used by hackers to try to gain access to systems and manipulate data; therefore, the following words are restricted: "select," "delete," "update," "insert," "drop" and "null".
  8. #5
  9. No Profile Picture
    Registered User
    Devshed Newbie (0 - 499 posts)

    Join Date
    Aug 2013
    Posts
    3
    Rep Power
    0
    There seams to be a few of Unicode General Categories missing, for example Nl, Zs etc.

    Also I could get Ll and Lu working separately but if I used union it wont work.


    Can I use fromUnicodeGeneralCategory to get any letter, both upper and lower or must I use Union to combine Ll and Lu?


    There seams to be a few of Unicode General Categories missing, for example Nl, Zs etc.

    If I want a expresson for upper and lower letters and numbers in all languages. how can I get that?

    I tried to use the union method but that doesn't work. Lu and Ll works when used separate.

    var patternLetterLowercase = fromUnicodeGeneralCategory('Ll');
    var patternLetterUppercase = fromUnicodeGeneralCategory('Lu');

    var patternLetters = union(patternLetterLowercase, patternLetterUppercase);


    var lettersonlyPattern = toRegex(patternLetters);

    lettersonlyPattern = '^' + lettersonlyPattern + '+$';

    var testPattern = new RegExp(lettersonlyPattern);

    return testPattern.test($.trim(val));


    Is there another way to do it or am I using "union" the wrong way

IMN logo majestic logo threadwatch logo seochat tools logo