Click here to Skip to main content
15,895,370 members
Please Sign up or sign in to vote.
1.00/5 (2 votes)
Hi all,
i need small help on one validation issue,
Textbox should accept starting with SV or AV with numbers. need reg expression to validate it.

Could you please help me to solve the issue.

Thanks in Advance!

What I have tried:

I have tried the following reg exp.
Regex VRegex =  new Regex(@"[SV]|[AS]\d{9}\.\d{1}");
Regex VRegex =  new Regex(@"{SV}|{AS}\d{9}\.\d{1}");
Posted
Updated 2-Dec-21 22:50pm
v5
Comments
Richard Deeming 3-Dec-21 4:50am    
Removing the content of your question after it has been answered is extremely rude. I have rolled back your destructive edit.

1 solution

Start by learning how regexes work: [SV] matches a single character, either an 'S' or a 'V', not the string "SV".

You need to add a "start of string" indicator as well (probably an "end of string" indicator will help also), and check that all you numbers will be exactly 9 digits, a decimal point, and a single digit to finish with.
In addition, you will need to "group things" in order to get the alternatives to work correctly.
Get a copy of Expresso[^] - it's free, and it examines and generates Regular expressions.

I could just give it to you, but you'd learn nothing from that, and it should take you no more than two minutes to build and test the regex in Expresso anyway. Give it a try, and if you can;t work it out, show us what you ended up with and I'll help further. But Regexes do ned to be understood, and the best way to do that is to create them! Give it a try - it is pretty simple, really!
 
Share this answer
 

This content, along with any associated source code and files, is licensed under The Code Project Open License (CPOL)



CodeProject, 20 Bay Street, 11th Floor Toronto, Ontario, Canada M5J 2N8 +1 (416) 849-8900