textbox validation

Collapse
This topic is closed.
X
X
 
  • Time
  • Show
Clear All
new posts
  • jothi.v81@gmail.com

    #1

    textbox validation

    hi,

    i am beginner to java script.

    i want to validate the textbox that it can accept numers only.and
    alphabets only.
  • Thomas 'PointedEars' Lahn

    #2
    Re: textbox validation

    jothi.v81@gmail .com wrote:
    i am beginner to java script.
    It is called JavaScript and has little if anything to do with Java.
    i want to validate the textbox that it can accept numers only.and
    alphabets only.
    <form action="..." ... onsubmit="retur n validate(this); ">
    <script type="text/javascript">
    function validate(f)
    {
    var es = f.elements;
    if (/\W/.test(es["foo"].value))
    {
    window.alert("O nly numbers and letters, please.");
    return false;
    }

    return true;
    }
    </script>
    ...
    <input name="foo">
    ...
    </form>

    See


    Look up the Unicode charts for the code points of the glyphs that you
    consider part of the alphabet as well (like those of Devanagari, Bengali,
    Gujarati or Gurmukhi):



    The solution can be found plenty of times with your favorite search engine.
    Please try that before you post next time.




    PointedEars
    --
    var bugRiddenCrashP ronePieceOfJunk = (
    navigator.userA gent.indexOf('M SIE 5') != -1
    && navigator.userA gent.indexOf('M ac') != -1
    ) // Plone, register_functi on.js:16

    Comment

    • Dr J R Stockton

      #3
      Re: textbox validation

      In comp.lang.javas cript message <4831B10F.40802 01@PointedEars. de>, Mon,
      19 May 2008 18:55:43, Thomas 'PointedEars' Lahn <PointedEars@we b.de>
      posted:
      >jothi.v81@gmai l.com wrote:
      >i want to validate the textbox that it can accept numers only.and
      >alphabets only.
      if (/\W/.test(es["foo"].value))
      That will, contrary to specification, accept the underline character.
      Please think before you write.

      It will also reject alphabetic characters such as á é í ó ú ij and those
      with umlauts; and all Russian Greek, Hangul, etc., letters. But
      probably the OP had not intended that they be allowed.


      --
      (c) John Stockton, nr London UK. ???@merlyn.demo n.co.uk Turnpike v6.05 MIME.
      Web <URL:http://www.merlyn.demo n.co.uk/- FAQish topics, acronyms, & links.
      Check boilerplate spelling -- error is a public sign of incompetence.
      Never fully trust an article from a poster who gives no full real name.

      Comment

      Working...