Click here to Skip to main content
15,883,848 members
Please Sign up or sign in to vote.
0.00/5 (No votes)
See more: , +
i have tried using reg ex alone but it can only check if it followed the format and I want a better way of getting input from user by automatically adding hyphen.

my reg ex: \b\d{2}-\d{9}-\d{1}

any 2digit-any 9digit-any 1digit number
Posted

Other then Masked textbox using Ajax, You will also find this simple TRICK[^] with simple JS useful.
 
Share this answer
 
Comments
gherard 8-Jan-11 11:25am    
this is exactly what i am looking for. thanks!
Try the MaskedEdit ASP.Net AJAX extender[^] or some other masked text box control.
 
Share this answer
 
Comments
Manfred Rudolf Bihy 7-Jan-11 16:50pm    
Good call! 5+
Sergey Alexandrovich Kryukov 7-Jan-11 17:23pm    
Masked edit is acceptable alternative (my 5), but "automatically adding hyphen" is absolutely not.
The user will be ripping if anything defeats the expected behavior of the text editor everyone is used to. Nothing should ever shift cursor, add/remove or replace any character. Relatively successful examples of Microsoft word and Visual Studio are just that kind of exclusions which only justify the rule.
Hiren solanki 7-Jan-11 23:13pm    
Good call Kythen.
gherard 8-Jan-11 11:25am    
good suggestion. I seemed to favor hiren's solution though and a js workaround is what i am really looking for. thanks btw.
Another, masked textbox custom control that you can look at and customize: Xtended TextBox[^]
 
Share this answer
 
Comments
gherard 8-Jan-11 11:26am    
thanks for providing another alternative.

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