Click here to Skip to main content
15,888,803 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more:
Hello Guys,
I am developing windows application using C#.
Can we use regular expression validation in windows application? How?
I want a string which contain starting 5 char Alphabets then 4 char numeric and 1 char Alphabet in sequence.
Regards,
Zuber Kazi
Posted
Comments
Menon Santosh 13-Feb-12 2:46am    
Yes we can, what is your string format is it like AAAAA1234A
ProEnggSoft 28-Mar-12 3:14am    
Please see my solution (2). It may also be helpful to you - PES.

Actually, yes you can.
How to: Search String Using Regular Expressions (C#)[^]
Regular Expressions Usage in C#[^]
System.Text.RegularExpressions.Regex Class[^]

And here is a cool site to find the regex you want and practice a bit with it... RegExr[^] (it's really easy to use!).
Hope these links can get you on your way! :)
 
Share this answer
 
Comments
Sergey Alexandrovich Kryukov 13-Feb-12 3:00am    
Sure, a 5.
--SA
Sander Rossel 13-Feb-12 3:26am    
Thanks SA :)
ProEnggSoft 28-Mar-12 3:07am    
Good links. +5
Expresso is good free tool to test regular expressions and it can be downloaded from

http://www.ultrapico.com/Expresso.htm[^]

In Windows forms, Validating event of control can be used to test the required string with Regex.IsMatch method for the required pattern. If it fails then set e.Cancel = true else set e.Cancel = false

For the pattern mentioned in the question the following regular expression can be used

^[a-zA-Z]{5}\d{4}[a-zA-Z]$
 
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