Results 1 to 2 of 2

Thread: Validating Alphanumeric

  1. #1

    Thread Starter
    Hyperactive Member
    Join Date
    Sep 2000
    Location
    Tennessee
    Posts
    279

    Validating Alphanumeric

    What's the best way in Javascript to validate that a field is alphanumeric?
    A cynic knows the price of everything but the value of nothing.

  2. #2
    Frenzied Member Acidic's Avatar
    Join Date
    Sep 2003
    Location
    UK
    Posts
    1,090
    Code:
    <script type="text/javascript">
    //now tested:
    var str = "skslkdrt492"
    regexp1 = /\d/
    regexp2 = /\w/
    bool = true
    for (i=0; i<str.length; i++)
        {
        if (str.charAt(i).search(regexp1) == -1 && str.charAt(i).search(regexp2) == -1)
            {
            bool = false
            }
        }
    if (bool == false)
        {
        //not alpha-numeric.
        }
    </script>
    Last edited by Acidic; May 5th, 2004 at 12:09 PM.
    Have I helped you? Please Rate my posts.

Posting Permissions

  • You may not post new threads
  • You may not post replies
  • You may not post attachments
  • You may not edit your posts
  •  



Click Here to Expand Forum to Full Width