Java script validation for numeric and text field

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • Thiyagusathya
    New Member
    • May 2007
    • 1

    Java script validation for numeric and text field

    Hi.,

    Please help me for java script validation for text and numeric field.
  • DeMan
    Top Contributor
    • Nov 2006
    • 1799

    #2
    Hi Thiyagusathya ,
    Welcome to the scripts. I am moving your post to the JavaScript forum where you will get a better response from javascript experts. In future you can find this by selecting the forums option on the blu bar at the top of the screen.
    I hope you find the answers you require

    Comment

    • acoder
      Recognized Expert MVP
      • Nov 2006
      • 16032

      #3
      Originally posted by Thiyagusathya
      Hi.,

      Please help me for java script validation for text and numeric field.
      Have a look at the validation links in the Offsite Links thread (sticky).

      Comment

      • helloiamhere
        New Member
        • May 2007
        • 5

        #4
        Originally posted by Thiyagusathya
        Hi.,

        Please help me for java script validation for text and numeric field.

        HI
        you can use the following function for the fields you want to validate

        Number Validation:

        [CODE=javascript]function numericValidate (string) {
        var intCharCode;
        for (var i = 0; i < string.length; i++) {
        intCharCode = string.charCode At(i);
        if (!((intCharCode >= 48 && intCharCode <= 57)))
        return false; (or)
        alert("it is not a number");
        }
        }[/CODE]


        String Validation:(it wont allow spaces between or at any place in the string)

        [CODE=javascript]function strValidate(str ing)
        {
        var testName =/^([a-z]|[A-Z]| )*$/;
        if(!testName.te st(string))
        {
        return false; (or) alert("Enter only string values");
        }
        }[/CODE]
        Last edited by gits; Feb 7 '08, 11:06 PM. Reason: added code tags

        Comment

        • eliza66
          New Member
          • Jun 2010
          • 1

          #5
          Originally posted by Thiyagusathya
          Hi.,

          Please help me for java script validation for text and numeric field.
          Basicallly When we trying to validate a form some time we need numeric validation for textbox.

          We can validate textbox by onkeypress event of the control By checking whether the keycode of the key pressed as the user types falls within the range of the number keys 48-57(i.e 0-9 and '.') ,if not belong to that range it will return false then it will disable the keypress action
          Last edited by acoder; Jun 16 '10, 03:19 PM. Reason: Don't add links to spam

          Comment

          Working...