Hi,
I have TextBox and I want to add validation using regular expression.
I want to allow only 20 alphabet or number in TextBox.
Example [A-Za-z0-9]{1,20}
Any idea about regular expression.
- Thanks
Loading
Know the answer? Post it — somebody with the same question will find it here.
Sign in to answer this question
It is the same account you read, post and publish with — and you will come straight back to this page.
VulpesPosted Jun 26, 2012, 10:46 AM
So, if you want to mix these in with English characters and spaces (subject to a maximum of 20 characters overall), I'd try:
@"^[\p{IsArabic}a-zA-Z\s]{1,20}$"
or if you want to precede the (maximum 20) English characters and spaces by any number of Arabic characters (including 0):
@"^\p{IsArabic}*[a-zA-Z\s]{1,20}$"
zohaib khanPosted Jun 27, 2012, 2:22 AM
Excellent many thanks.
Zohaib.
zohaib khanPosted Jun 26, 2012, 10:19 AM
Any idea about regular expression if I use English and Arabic with following
@"^[a-zA-Z\s]{1,20}$"
I tried
@"^[?-?\s]*[a-zA-Z\s]{1,20}$" but not working
Unicode Regular Expressions will help?
http://www.regular-expressions.info/unicode.html#script- Thanks
zohaib khanPosted Jun 26, 2012, 8:51 AM
It is working :)
VulpesPosted Jun 26, 2012, 8:35 AM
string regExp = @"^[a-zA-Z0-9]{1,20}\s*$";
If you want to allow spaces anywhere within the string but limited overall to 20 characters, use:
string regExp = @"^[a-zA-Z0-9\s]{1,20}$";
zohaib khanPosted Jun 26, 2012, 8:30 AM
it is working and if I want to allow spaces adding + sign not working.
^[A-Za-z]{1,20}+$
OR
^[A-Za-z\s]{1,20}$
I am getting exception regarding - Nested quantifier +.
Posted Jun 26, 2012, 8:25 AM
[a-zA-Z0-9]{20}
Online RegEx tester
VulpesPosted Jun 26, 2012, 8:07 AM