text box validation

Collapse
X
 
  • Time
  • Show
Clear All
new posts
  • prabhunew2005
    New Member
    • Aug 2006
    • 10

    text box validation

    I am doing text box validation in form.

    I did the following validations.

    1)Special characters like $,#,etc should not be allowed to enter by user.
    2)Only alphanumerical characters should be allowed to enter in text box.
    3)The maximum length is 10. After that the user should not be allowed to enter any character.

    I am facing the following problem.

    pbm:
    I entered the characters upto maximum length, then i want to change the value. I pressed SHIFT + HOME key. All the values in text box are selected. Then i enter a new character to replace the old string. But the string could not be deleted when new character key is pressed.


    Please give solution for this. Otherwise please give the perfect validation sample coding.

    Please help me. Advance thanks.
  • acoder
    Recognized Expert MVP
    • Nov 2006
    • 16032

    #2
    [HTML]<script type="text/javascript">
    function alphaNumOnly(e) {
    keycode = e.keyCode || e.which;
    keychar = String.fromChar Code(keycode);
    keycheck = /\d|[a-z]/i
    return keycheck.test(k eychar);
    }
    </script>

    <form>
    <input type="text" onkeypress="ret urn alphaNumOnly(ev ent)" maxlength="10">
    </form>[/HTML]

    Comment

    Working...