|
-
Dec 17th, 2007, 01:51 PM
#1
Thread Starter
Sleep mode
[2.0] regex question
How would you go about doing this using regex :
I want to validate "Age" field which complies to these rules:
1.doesn't accept "zero" at the beginning.
2.doesn't excced 3 digits.
3.accept 2 or 3 digits.
examples of valid ages: 20 , 38,102
Sorry , can't construct this little regex string
Thank u for any help !
Last edited by Pirate; Dec 18th, 2007 at 10:33 AM.
-
Dec 17th, 2007, 04:06 PM
#2
-
Dec 18th, 2007, 06:32 AM
#3
Thread Starter
Sleep mode
Re: [2.0] regex question
 Originally Posted by wild_bill
I tested in Expresso,returned no results!so it's not working
-
Dec 18th, 2007, 08:16 AM
#4
I wonder how many charact
Re: [2.0] regex question
WildBill's regex would work if you enclose it in paranthesis:
^([1-9][0-9]{0,2})$
However, it also creates a grouping on the last digit.
Try this:
^([1-9][0-9][0-9]*)*
-
Dec 18th, 2007, 08:41 AM
#5
Thread Starter
Sleep mode
Re: [2.0] regex question
 Originally Posted by nemaroller
WildBill's regex would work if you enclose it in paranthesis:
^([1-9][0-9]{0,2})$
However, it also creates a grouping on the last digit.
Try this:
^([1-9][0-9][0-9]*)*
same result..no matching
-
Dec 18th, 2007, 10:26 AM
#6
I wonder how many charact
Re: [2.0] regex question
How do you mean no matches?
I get many matches.
Try the same regex in Regex lib:
http://regexlib.com/RETester.aspx
-
Dec 18th, 2007, 10:26 AM
#7
Re: [2.0] regex question
I tested it with vb.net, and it worked.
Code:
Dim rx As New Regex("^[1-9][0-9]{0,2}$")
Console.WriteLine(rx.IsMatch("20"))
Console.WriteLine(rx.IsMatch("38"))
Console.WriteLine(rx.IsMatch("102"))
Console.WriteLine(rx.IsMatch("3"))
Console.WriteLine(rx.IsMatch("1022"))
Console.WriteLine(rx.IsMatch("03"))
-
Dec 18th, 2007, 10:33 AM
#8
Thread Starter
Sleep mode
Re: [2.0] regex question
Sorry,multiline was disabled in Expresso..all regex are working
Thanks all
-
Dec 18th, 2007, 11:19 AM
#9
Re: [2.0] regex question
You might consider modifying so no values > 199 are allowed.
-
Dec 18th, 2007, 12:54 PM
#10
I wonder how many charact
Re: [2.0] regex question
He could have meant age as in the number of days of an outstanding invoice.
He never clarified that though.
-
Dec 18th, 2007, 01:07 PM
#11
Thread Starter
Sleep mode
I will consider that next time
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|