Go Back   CodingForums.com > :: Server side development > ASP.NET

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 01-11-2013, 04:06 AM   PM User | #1
simon47
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
simon47 is an unknown quantity at this point
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
simon47 is offline   Reply With Quote
Old 01-11-2013, 05:37 PM   PM User | #2
j4v3d
New Coder

 
Join Date: Mar 2009
Location: UK
Posts: 34
Thanks: 6
Thanked 0 Times in 0 Posts
j4v3d is an unknown quantity at this point
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?
__________________
MJCoder
Twitter
j4v3d is offline   Reply With Quote
Old 01-11-2013, 07:20 PM   PM User | #3
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
alykins is offline   Reply With Quote
Users who have thanked alykins for this post:
simon47 (01-15-2013)
Old 01-15-2013, 10:53 PM   PM User | #4
simon47
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
simon47 is an unknown quantity at this point
thanks it works
simon47 is offline   Reply With Quote
Old 01-16-2013, 09:10 PM   PM User | #5
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Old 01-17-2013, 01:22 PM   PM User | #6
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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)?
__________________

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

Last edited by alykins; 01-17-2013 at 04:18 PM..
alykins is offline   Reply With Quote
Old 01-17-2013, 08:51 PM   PM User | #7
Old Pedant
Supreme Master coder!

 
Old Pedant's Avatar
 
Join Date: Feb 2009
Posts: 23,249
Thanks: 59
Thanked 3,999 Times in 3,968 Posts
Old Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to allOld Pedant is a name known to all
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.
Old Pedant is offline   Reply With Quote
Users who have thanked Old Pedant for this post:
alykins (01-18-2013)
Old 01-18-2013, 12:43 PM   PM User | #8
alykins
Senior Coder

 
alykins's Avatar
 
Join Date: Apr 2011
Posts: 1,608
Thanks: 37
Thanked 183 Times in 182 Posts
alykins will become famous soon enough
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
alykins is offline   Reply With Quote
Old 01-23-2013, 10:40 AM   PM User | #9
simon47
New to the CF scene

 
Join Date: Jan 2013
Posts: 6
Thanks: 1
Thanked 0 Times in 0 Posts
simon47 is an unknown quantity at this point
nice and interesting...thanks for that very important information..it helped me alot for my studies..thanks
simon47 is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
Rate This Thread
Rate This Thread:

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT +1. The time now is 10:15 AM.


Advertisement
Log in to turn off these ads.