Reg.Exp for alphanumeric [Resolved]

Posted by Thiru under Regular Expressions on 6/19/2011 | Points: 10 | Views : 2088 | Status : [Member] | Replies : 10
Hi,
can you let me know the Regular Expression
which should check if alpha and numeric both are present or not
if present it should allow or else alert the err msg.




Responses

Posted by: Ndebata on: 6/20/2011 [Member] Starter | Points: 50

Up
0
Down

Resolved
Hi
As It must start with VT
You can use some thing like this
^VT[0-9]{4,7}$ 

Thanks,
Debata

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: SheoNarayan on: 6/19/2011 [Administrator] HonoraryPlatinum | Points: 25

Up
0
Down
Hi Thiru,

Thanks for asking the question. I think the permanent solution of your problem is to learn the regular expression. Below are great resources to learn RegularExpression and you would be able to solve your problem easily.

Learn RegularExpression from http://www.dotnetfunda.com/articles/article1260-b-ball-c-cat-d-dog-learning-regex-regular-expression-the-easy-wa-.aspx

Examples and great regular expression library

http://www.regxlib.com/
http://www.regular-expressions.info/examples.html

Thanks

Regards,
Sheo Narayan
http://www.dotnetfunda.com

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks for your valuable link.
for validating an invoice number must start with "VT" followed by numbers min. 4 and max. 7
like: VT00001

I used: /^[a-zA-Z]{2}[0-9]{4,7}$/; (in javascript, html page)
but its not working.
Please let me know where i made a mistake and what is the correct Reg.Exp for the same.

expecting your valuable reply in this regard.
Regards,
Thiru.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Lakn2 on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
try this

Regex obj = new Regex("^[a-zA-Z]{2}[0-9]{4,7}");


page.registerstarupscript("<script>","<script>alert('"+ (obj.IsMatch("sh4567").ToString())"')</script>") ;


Thanks&Regards
LakshmiNarayana Nalluri.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks its working fine with:
^VT[0-9]{4,7}$ 


Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hi Debata,
Thanks for your valuable support.
Let me know whether we can validate the typed value is exactly divided by 25 or not.
(generally we use this using mod function)

But i need to do using reg. exp. validation

expecting your valuable reply in this regard.
Regards,
Thiru.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Hello Sir,
If the last two digit of any number is among these ( "00","25","50","75") then number is divided by 25. Then expression will be similar to
^[0-9]{0,12}(00|25|50|75)$ 

Thanks,
Debata

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
Thanks for your reply Debata.
I just mention 25 for sample.
but it will differ depending on conditions. It may be required for 2500 and 500
i mean: validate the typed value is exactly divided by 2500 or not.

As in your above reply: we can not type all the possible values like ( "00","25","50","75") to check.
-- am i right

expecting your valuable reply in this regard.
Regards,
Thiru.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Ndebata on: 6/20/2011 [Member] Starter | Points: 25

Up
0
Down
No its not possible for all.
regular expression is just about patterns, if you know the pattern then only you can apply it.

Thanks,
Debata

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Thiru on: 6/21/2011 [Member] Starter | Points: 25

Up
0
Down
oh okay,
Thanks for your valuable time here.
Regards,
Thiru.

Thiru, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response