Form validation check - no numerals

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • sweetamy
    New Member
    • Jul 2007
    • 2

    Form validation check - no numerals

    i am making an html form......it should check the values before accepting the data in the database,,,,,,, ,,,,,,a field name USER NAME should check if the value entered is only a character value nd no numerals,,,nd if numerals r entered it should raie an exception i.e. alert msg...........h ow is it done using java script......... .
    thanx
  • shoonya
    New Member
    • May 2007
    • 160

    #2
    say val=the value entered by user

    [HTML]
    for(i=0; i<val.length; i++){
    if(check val[i] for no) {
    alert('msg')
    return false
    }
    }
    return true
    [/HTML]

    for advance use you can use regular expression

    Comment

    • gits
      Recognized Expert Moderator Expert
      • May 2007
      • 5388

      #3
      hi ...

      the regEx is the cool way ... ;)

      [CODE=javascript]
      // our regEx (/\d/g) checks for numbers in the string we
      // give as parameter to the built in js-method test(value);

      // this returns false
      /\d/g.test('abcg');

      // this returns true
      /\d/g.test('abc3g') ;
      [/CODE]

      of course you may use the shown loop above and to check whether a part (val[i]) is a number or not ... you may use the isNaN(value); function ... that returns false when value is a number ;) (isN(ot)aN(umbe r) -> simple name of that function isn't it? ) ...

      kind regards

      Comment

      • acoder
        Recognized Expert MVP
        • Nov 2006
        • 16032

        #4
        Changed thread title.

        MODERATOR

        Comment

        Working...