RegularExpressionValidator - Email addresses, Social Security numbers, Phone numbers

Q.  If you want to validate the email addresses, Social Security numbers, phone numbers, and dates types of data, which validation control will be used?
- Published on 28 Jul 15

a. RegularExpressionValidator
b. CompareValidator
c. RequiredFieldValidator
d. None of the above

ANSWER: RegularExpressionValidator
 

    Discussion

  • Raj Singh   -Posted on 14 Sep 15
    The RegularExpressionValidator control performs its validation according to the regular expression. This control validates email addresses, Social Security numbers, phone numbers, and dates types of data. The control uses the ValidationExpression property to set a valid regular expression that is applied to the data that is to be validated.

    Example

    <asp:RegularExpressionValidator
    id=”regExpEmail”
    ControlToValidate=”txtEmail”
    Text=” (Invalid email)”
    ValidationExpression=”\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*
    Runat=”server” />

Post your comment / Share knowledge


Enter the code shown above:

(Note: If you cannot read the numbers in the above image, reload the page to generate a new one.)