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#?

有帮助吗?

解决方案

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

其他提示

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

许可以下: CC-BY-SA归因
不隶属于 StackOverflow
scroll top