 |
| ASP.NET 2.0 Professional If you are an experienced ASP.NET programmer, this is the forum for your 2.0 questions. Please also see the Visual Web Developer 2005 forum. |
Welcome to the p2p.wrox.com Forums.
You are currently viewing the ASP.NET 2.0 Professional section of the Wrox Programmer to Programmer discussions. This is a community of software programmers and website developers including Wrox book authors and readers. New member registration was closed in 2019. New posts were shut off and the site was archived into this static format as of October 1, 2020. If you require technical support for a Wrox book please contact http://hub.wiley.com
|
|
|
|

May 23rd, 2009, 11:42 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Regular expression to validate Digit alphabet DigitDigit
Hi,
I need a regex to allow the user to insert type in a text box strings that maches this pattern:
DigitAlphabet(upper case)DigitDigit i.e the length of the input must be 4 and it must consist of a number a and alphabet number number for example:
2R67 or 0K98 or 3W77
but not 2r67 or ok98 or 2w77
many thanks for your help
|
|

May 23rd, 2009, 12:13 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
HEllo.. Since there are only 4 chars, isn't faster to just check the char one at a time???
to check if one is uppercase, match the char with the same char.uppercase.
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

May 23rd, 2009, 07:21 PM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Quote:
Originally Posted by gbianchi
HEllo.. Since there are only 4 chars, isn't faster to just check the char one at a time???
to check if one is uppercase, match the char with the same char.uppercase.
|
Thanks gbianchi for your reply,
If i write a function to check each charector one by one, how can i use it with RegularExpressionValidator control.
If had the regExp I asigned ValidatorExpression to the RegExp pattern.
Thanks
|
|

May 23rd, 2009, 07:26 PM
|
|
Friend of Wrox
|
|
Join Date: Jun 2003
Posts: 2,189
Thanks: 5
Thanked 59 Times in 57 Posts
|
|
you can't. If you want to use the control you need the reg exp. You never said you need it for the control, So i didn't assume that.
__________________
HTH
Gonzalo
================================================== =========
Read this if you want to know how to get a correct reply for your question.
(Took that from Doug signature and he Took that from Peter profile)
================================================== =========
My programs achieved a new certification :
WORKS ON MY MACHINE
================================================== =========
I know that CVS was evil, and now i got the proof.
================================================== =========
|
|

May 23rd, 2009, 08:27 PM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
|
|
When I'm building regular expressions, I always find the cheat sheet at regexlib.com handy - http://www.regexlib.com/CheatSheet.aspx Also their tester is quite useful - http://www.regexlib.com/RETester.aspx
For your problem you need to match numbers (\d) and upper-case letters ([A-Z]). Also to ensure they only enter 4 characters you want to add start and end markers round it (^ and $). So your expression becomes:
HTH
Phil
PS. You could use a separate function to do your own check by using a CustomValidator, but it's somewhat overkill to shave off a couple of nanoseconds of processing time
Last edited by philip_cole; May 23rd, 2009 at 08:31 PM..
|
|

May 26th, 2009, 06:11 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Hi Philip,
First thanks for your help.
I tried your regex code but the problem is in the css file i have set the text box text uppercase and this casuses the vilidation error message to fire up.
I need to set the textbox text to upper so that the user does not need to press Shift Key.
Any idea how this can be sorted.
Thanks
Quote:
Originally Posted by philip_cole
When I'm building regular expressions, I always find the cheat sheet at regexlib.com handy - http://www.regexlib.com/CheatSheet.aspx Also their tester is quite useful - http://www.regexlib.com/RETester.aspx
For your problem you need to match numbers (\d) and upper-case letters ([A-Z]). Also to ensure they only enter 4 characters you want to add start and end markers round it (^ and $). So your expression becomes:
HTH
Phil
PS. You could use a separate function to do your own check by using a CustomValidator, but it's somewhat overkill to shave off a couple of nanoseconds of processing time
|
|
|

May 26th, 2009, 06:57 AM
|
|
Friend of Wrox
|
|
Join Date: Sep 2005
Posts: 166
Thanks: 2
Thanked 33 Times in 33 Posts
|
|
I don't think you can really force it as uppercase, unless you do some javascript like:
Code:
<input type="text" value="" name="thecode" onkeyup="this.value = this.value.toUpperCase()" />
but even that isn't foolproof
If the codes are always going to be uppercase, its probably easier and more reliable, as you aren't forcing the user to enter it correctly, to make the regexp case insenitive and change the value to uppercase in the back end, e.g. in the page code or your database insert.
Phil
|
|

June 3rd, 2009, 05:32 AM
|
|
Authorized User
|
|
Join Date: Jul 2006
Posts: 25
Thanks: 0
Thanked 0 Times in 0 Posts
|
|
Regular expression to validate Digit alphabet DigitDigit
Hi Phili,
first thanks for your help with this issue.
Now I have added
Code:
<input type="text" value="" name="thecode" onkeyup="this.value = this.value.toUpperCase()" />
into the textbox control but now the regEx does not fire up i.e
any idea?
Thanks
Rao
Quote:
Originally Posted by philip_cole
I don't think you can really force it as uppercase, unless you do some javascript like:
Code:
<input type="text" value="" name="thecode" onkeyup="this.value = this.value.toUpperCase()" />
but even that isn't foolproof
If the codes are always going to be uppercase, its probably easier and more reliable, as you aren't forcing the user to enter it correctly, to make the regexp case insenitive and change the value to uppercase in the back end, e.g. in the page code or your database insert.
Phil
|
|
|
 |