Question

I am wondering if I have two text boxes for Phone and Mail how can I allow only digits (let's say US standard 1-234-567-8910) and only a real e-mail(aaaaaaa*@bbb.*cc) to my text boxes correspondingly in c#?

Was it helpful?

Solution

Use Masked TextBox For this and put Validation on TextBox Validating Event
Try this Link Phone Number Validation it may help you

OTHER TIPS

you can use a jQuery plugin named mask click here

In WinForms you can use the ErrorProvider in conjunction with the Validating event to handle the validation of user input. The Validating event provides the hook to perform the validation and ErrorProvider gives a nice consistent approach to providing the user with feedback on any error conditions. You can use regular-expression validation inside this event to check the pattern of email or phone number. More detail is HERE

For WebForm: You can use HTML 5 validation, which is very easy use and understand. Here is link It is client side validation so it is very useful to you. In example at above provided link, use validation attributes in server control as it is.

For WinForm : You can use maskedTextBox link

Licensed under: CC-BY-SA with attribution
Not affiliated with StackOverflow
scroll top