Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 9 of 9
  1. #1
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts

    help with "regular expression validator"

    im creating a login page but for the ID part it requires a validation nd the ID should be "s11111111" and there should be different numbers in the ID for multiple students....how can i validate this under the regular expression editor so that it accepts the ID type listed above? i need a validation expression for it..can anyone please help me with these

  • #2
    New Coder
    Join Date
    Mar 2009
    Location
    UK
    Posts
    34
    Thanks
    6
    Thanked 0 Times in 0 Posts
    Quote Originally Posted by simon47 View Post
    im creating a login page but for the ID part it requires a validation nd the ID should be "s11111111" and there should be different numbers in the ID for multiple students....how can i validate this under the regular expression editor so that it accepts the ID type listed above? i need a validation expression for it..can anyone please help me with these
    Surely when they are logging you would want to be able to store the ID for that user only and if another user signs up to the website he/she has their own ID generated.

    Or are you doing it so the ID is what ever they set?

  • #3
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,776
    Thanks
    41
    Thanked 196 Times in 195 Posts
    I don't know all the BI rules of your validation, but this regex should work for you

    ^([a-z][A-Z]{0,1})+\d{1,8}

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • Users who have thanked alykins for this post:

    simon47 (01-15-2013)

  • #4
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    thanks it works

  • #5
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Quote Originally Posted by alykins View Post
    I don't know all the BI rules of your validation, but this regex should work for you

    ^([a-z][A-Z]{0,1})+\d{1,8}
    That's not correct, Alykins. Not really even close.

    That reads:
    -- no characters BEFORE what follows (good)
    -- a lower case letter
    -- FOLLOWED by an optional upper case letter (huh???)
    -- that pattern (lower then optional upper) repeated 1 *OR MORE* times
    -- followed by from 1 to 8 digits
    -- any number of any kinds of characters AFTER the preceding.

    So that expression would *ACCEPT*:
    s11111111 (as expected)
    cZ3xx@#$--+111BB (after the \d{1,8}, *ANYTHING* is allowed)
    s33333333333333333333333333333333333333333333 (8 digits accepted, but with no limit on what follows them)
    aBcDeFgHiJKlMn4 (lower upper repeated any number of times, 1 digit minimum okay)
    zzzzzzzzz77777777 (lower [no optional upper] repeated)
    and many others.

    From what he posted, I think it should be:
    ^[a-zA-Z]\d{8,8}$

    Which reads:
    -- no characters BEFORE what follows
    -- one letter, either upper or lower case
    -- followed by exactly 8 digits
    -- no characters AFTER the preceding.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • #6
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,776
    Thanks
    41
    Thanked 196 Times in 195 Posts
    thanks for correction- my regex is not too great... i thought the {0,1} specified the first place on the substring (spec'ing it as an a-zA-Z) and then the + \d part was spec'ing only digits for the substring 1-8 {1,8} making it only 9 chars long... obviously not- so what do the {}'s mean?

    Edit: Also are regex's standardized across languages (do you know)?
    Last edited by alykins; 01-17-2013 at 04:18 PM.

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #7
    Supreme Master coder! Old Pedant's Avatar
    Join Date
    Feb 2009
    Posts
    26,198
    Thanks
    80
    Thanked 4,453 Times in 4,418 Posts
    Each *group* of characters in [...] is treated as "choose one of these".

    So when you did
    [a-z][A-Z]
    that said "choose a lower case letter" and then "choose an upper case letter".

    But then you actually used
    [A-Z]{0,1}
    which means "choose that expression [in this case upper case letter] from 0 to 1 times.

    {a,b} means "repeat from a through b times".
    {0,1} is equivalent to just ? -- as in [A-Z]?
    {1,} is equivalent to just + -- as in [A-Z]+
    {0,} is equivalent to just * -- as in [A-Z]*

    Anyway, you then grouped all that:
    ([a-z][A-Z]{0,1}) -- lower case letter followed by 0 through 1 upper case letters
    and added the +
    ([a-z][A-Z]{0,1})+
    and as I just said, the + is equivalent to {1,} which means 1 through ANY NUMBER of occurrences
    So
    ([a-z][A-Z]{0,1})+ means "lower case letter followed by optional upper case letter and the whole thing repeated one or more times"

    aaaaaaaaaaaaaaaBaBaBaBaBaaaaaaaaaaa would fit that pattern, just for example.

    You then did
    \d{1,8}
    which means (as above) "any digit, repeated 1 through 8 times." SO
    7
    7131
    871122
    81712290
    would all match that.

    But then the big mistake you made was in omitting the $ at the end. Without that, your expression places NO LIMIT on what can follow the REQUIRED part!!!

    *********

    Not all features of regular expressions are standard across all languages. For example, I have seen some where \d is not recognized as being the same as [0-9]. But most features are the same, including the use of ( ) for grouping, [...] for character choices, ^ and $ for beginning/ending of text matches, and {...} for repetition counts. I don't think I 've seen any language that doesn't support all those.

    MySQL has some really funky requirements, just to pick the one oddball I am most familiar with. But it only takes a couple of minutes looking at their docs to get them right.
    An optimist sees the glass as half full.
    A pessimist sees the glass as half empty.
    A realist drinks it no matter how much there is.

  • Users who have thanked Old Pedant for this post:

    alykins (01-18-2013)

  • #8
    Senior Coder alykins's Avatar
    Join Date
    Apr 2011
    Posts
    1,776
    Thanks
    41
    Thanked 196 Times in 195 Posts
    Thanks for that info- I hope it is of use to OP as well
    I have a Regex snap-in but it only tells you if you are *sort of* right... ie it was saying mine was right, but only bc I didn't know all the wrong ones that would get through. Nice break down, the msdn Regex class is a little cryptic (IMO); I need to practice

    I code C hash-tag .Net
    Reference: W3C W3CWiki .Net Lib
    Validate: html CSS
    Debug: Chrome FireFox IE

  • #9
    New to the CF scene
    Join Date
    Jan 2013
    Posts
    6
    Thanks
    1
    Thanked 0 Times in 0 Posts
    nice and interesting...thanks for that very important information..it helped me alot for my studies..thanks


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •