Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 3 of 3

Thread: Data validation

  1. #1
    New Coder
    Join Date
    Sep 2011
    Posts
    78
    Thanks
    15
    Thanked 0 Times in 0 Posts

    Data validation

    I am new to html programming so i am just wondering if this is at all possible to do in HTML i know in Visual Basic programming you could validate the data the user enters in text fields like IsNumeric etc. to make sure the user only entered in numeric for certain fields. I want to know if there is a way i can do this in HTML

    I have seen some example of people using JavaScript to do this type of data validation but i am wondering if there is a way to do it without the help of javascript ???

  • #2
    New Coder
    Join Date
    Sep 2011
    Posts
    78
    Thanks
    15
    Thanked 0 Times in 0 Posts
    Also Is there a way to do something like this: lets say a zip code text field would only need to be 5 characters long (numeric) FOR the United States e.g 71458

    can a text field be fixed to only allow the user to enter in 5 numeric characters only?

  • #3
    The fat guy next door VIPStephan's Avatar
    Join Date
    Jan 2006
    Location
    Halle (Saale), Germany
    Posts
    8,695
    Thanks
    6
    Thanked 1,011 Times in 984 Posts
    Let me answer your second question first: To limit the amount of characters that can be written in a text input you set the maxlength attribute.
    Code:
    <input type="text" maxlength="25">
    The above limits the character count to 25. And with the size attribute you can influence the basic width of the input. I. e. a size="5" would make the input wide enough to show five characters at once.

    Now, your first question is a little more elaborate. The short answer is: it’s not possible with HTML alone. You need to use a server side script to validate the form input and can enhance user friendliness with JavaScript validation. The long answer is: It may be partly possible in the future version of HTML (that is HTML 5). As far as I can see there is the pattern attribute which can be set to a regular expression against which the browser will validate the input.

    But here comes the big however: Besides probably not being supported in a lot of browsers for quite a while yet this is still client-side validation only and is unreliable at best. For example, using Firebug or any similar debugging tool in other browsers I can just remove attributes or change attribute values on the fly and then submit the form with “wrong” data. You still need to do server side validation at all times if you want to make sure. JavaScript today and HTML 5 in future won’t save you from doing that.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •