Join the social network of Tech Nerds, increase skill rank, get work, manage projects...
  • Pattern Attribute in Html5

    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 0
    • 902
    Comment on it

    Pattern Attribute:

    Pattern attribute is used for input field validation  and used  to provide  a regular expression which is used to match  the input fields value whether the value is according to the pattern specified or not.


    When user  enter  a value in the input field and if the value entered is  not as per the  expected format, then a error is thrown and our form will not submit until user does not provide correct format value.


    <input pattern="regexp">

    Attribute Value:

    Value         Description
    regexp  Specifies a regular expression that the input field value is checked    against


    <!DOCTYPE html>
    <form action="">
    <p>Name: <input type="text" name="username" placeholder="Username"></p>
    <p>Address: <input type="text" name="username" placeholder="Username"></p>
    <p>Phone No: <input type="text" name="phone" pattern="[0-9]{10}" title="ten digit number only">
    <p><input type="submit"></p>

    In the above example in the phone number field we have used pattern attribute and this field will only take 10 digits number otherwise the form will not submit.

 0 Comment(s)

Sign In

Sign up using

Forgot Password
Fill out the form below and instructions to reset your password will be emailed to you:
Reset Password
Fill out the form below and reset your password: