isNaN function on a textbox in a form

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • myza123
    New Member
    • Sep 2014
    • 2

    isNaN function on a textbox in a form

    I am using HTML and JS to make a form, but one of the text boxes needs to validate that it will only accept digits as it is for a number, but I can't figure out how to do this with the isNaN function.
    PS it also has to be exactly four digits long

    Any help would be appreciated thanks
  • Dormilich
    Recognized Expert Expert
    • Aug 2008
    • 8694

    #2
    HTML5 solution
    Code:
    <input type="number">
    if number boxes are not supported:
    Code:
    // 'input' be the text box DOM element
    if (isNaN(input.value)) {
        // validation failed
    }

    Comment

    • myza123
      New Member
      • Sep 2014
      • 2

      #3
      ok, but now when i click submit with only numbers in the textbox, it still shows the dialog saying you must enter digits only

      Comment

      • Dormilich
        Recognized Expert Expert
        • Aug 2008
        • 8694

        #4
        show your code.

        Comment

        Working...