Click here to Skip to main content
15,885,537 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
Hello Developers

I am trying to applying validation in Textbox control for limiting empty space in control. Following is the Regular Expression code I'm using:


Regularexpression validationexpression="^[^-\s][a-zA-Z0-9_\s-]+$" errortext="" />

Now my requirement is:
1- User should not enter empty space in begining. (Working fine)
2- Textbox limit is upto 10 numbers, user will able to enter as much as number he wants, no validation if he enter less than 10 numbers. (Working fine.)
3- validation should prompt if user enter the numbers like this "111 111 ", means show validation if there is empty space between numbers. (Not working)

Currently I'm using following Regular Expression to achieve this thing, please let me know or update my regular expression so I can achieve this requirement.

Regularexpression validationexpression="^[^-\s][a-zA-Z0-9_\s-]+$" errortext="" />

Thank you.

Regards,
Posted
Updated 18-Oct-14 2:19am
v3

 
Share this answer
 
Comments
Member 9207317 19-Oct-14 23:47pm    
Thanks @amit for your reply but it's not fullfil my requirement, As I wrote in my question
I need all the following requirements fulfill in one regular experssion:

1- User should not enter empty space in begining. (Working fine)
2- Textbox limit is upto 10 numbers, user will able to enter as much as number he wants, no validation if he enter less than 10 numbers. (Working fine.)
3- validation should prompt if user enter the numbers like this "111 111 ", means show validation if there is empty space between numbers. (Not working)

So my 3rd requirement is not completed in my current regular expression, I have checked the link provided by you it's not giving user option for enter numbers upto 10 digits, user can enter all 10 numbers or 3-4 numbers (Maximum limit is 10 numbers but user can enter like "2345" only 4 in starting because this field is used for telephone extension).

Please suggests how can I achieve this.

Regards,
Hello

Thanks for your help, Now it's working fine, actually I had used the masking in devExpress textbox due to which the regular experession not working fine and giving issues. I have removed it now and it's working correctly. For limiting the length to 10 digits I have used the property MaxLength="10". Currently I'm using the following Regular Expression which is working fine:

^[a-zA-Z0-9_-]{1,10}$

Many Thanks.

Regards,
 
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