heyday2004
asked on
What is a good Regular Expression for 6 digit input validation?
The validation requirement is:
1. user can EITHER input 1 to 6 digit number
2. OR any string starting with R(r) followed by 1 to 5 digit numbers. i.e. any of below input is valid:
1, r2, R23333, 234, 555555
I wrote: ValidationExpression="\d{1 ,6}" for the first case and worked well. But what is the good regular expression to meet all the two requirements? Thanks a lot!
1. user can EITHER input 1 to 6 digit number
2. OR any string starting with R(r) followed by 1 to 5 digit numbers. i.e. any of below input is valid:
1, r2, R23333, 234, 555555
I wrote: ValidationExpression="\d{1
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
I tested mine also and it works correctly
but does it also match "12345678"?
ozo,
heyday only requires 6 digits without r and 5 digits with r at the begining
heyday only requires 6 digits without r and 5 digits with r at the begining
>> I tested mine also and it works correctly
It shouldn't match "R123456".
I think yours should be
boolean b = Pattern.matches("\\d{1,6}| [r]\\d{1,5 }|[R]\\d{1 ,5}","R512 35");
It shouldn't match "R123456".
I think yours should be
boolean b = Pattern.matches("\\d{1,6}|
"\\A[Rr\\d]?\\d{1,5}\\z"
ASKER CERTIFIED SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
zzynx u r right,
just miss typed it
thank u
just miss typed it
thank u
>> zzynx u r right, just miss typed it
>> thank u
No problem. Nobody's perfect ;°)
>> thank u
No problem. Nobody's perfect ;°)
I think i need to changed my old thick glasses :-) and yes "\\d{1,6}|[Rr]\\d{1,5}" is better
I thought my expressions were simpler, and do not match "12345678"
>> I thought my expressions were simpler
That's your good right of course.
No offense meant :)
>> and do not match "12345678"
None of the others did match that one, I think.
LOL. Apparantly we can't "read" each others regular expressions.;°)
That's your good right of course.
No offense meant :)
>> and do not match "12345678"
None of the others did match that one, I think.
LOL. Apparantly we can't "read" each others regular expressions.;°)
possibly even simpler - "^[\\dRr]\\d{5}$"
nope, meant to write this: "^[\\dRr]\\d{0-5}$"
That matches "R"
argh, third time lucky.... "^[\\dRr]\\d{0,5}$"
(so much for simplicity! I must remember to get the first cup of coffee in before posting in future :-))
(so much for simplicity! I must remember to get the first cup of coffee in before posting in future :-))
SOLUTION
membership
This solution is only available to members.
To access this solution, you must be a member of Experts Exchange.
Conclusion: All roads lead to Rome
Well, lots of roads ;°)
Well, lots of roads ;°)
doesn't that match "1\n"?
ozo, nope (the $ stops that)
zzynx, yup, the only problem is reading the map :-)
zzynx, yup, the only problem is reading the map :-)
I think we r all uselessly dwelling arround and the asker seems not interested any more or maybe already found the solution by himself :-)
cheers!
cheers!
ASKER
hey, guys. sorry came back late. thanks a lot so much. you guys are real regular expression experts. thanks again!
Thanks for accepting
These all print "true":
System.out.println( "1".matches("\\d{1,6}|[Rr]
System.out.println( "r2".matches("\\d{1,6}|[Rr
System.out.println( "R23333".matches("\\d{1,6}
System.out.println( "234".matches("\\d{1,6}|[R
System.out.println( "55555".matches("\\d{1,6}|