www.webdeveloper.com
Results 1 to 2 of 2

Thread: Form Validation not working. Pls help.

  1. #1
    Join Date
    Nov 2011
    Posts
    12

    Form Validation not working. Pls help.

    Hi:

    I have a form input field that need to be validated with at least 5 character and must contain one letter and 1 number. But it is not working. Below is my code. Please help. Thank you.

    Code:
    <form id="search_mini_form" action="/catalogsearch/result/" method="get" target="frame1">
    <div class="form-search"><label for="search">Search:</label> 
    <input id="search" class="input-text" type="text" name="q" value=""  /> 
    <button class="button" title="Search" type="submit" ><span><span>Search</span></span></button>
    
    <script type="text/javascript">
    <!--
    function checkserial(){
    var reg = /^.*(?=.{4,10})(?=.*\d)(?=.*[a-zA-Z]).*$/i //regular expression defining a 5 digit number
    if (document.search_mini_form.q.value.test(reg)==-1) //if match failed
    alert("Please enter a valid serial number.")
    }
    -->
    </script>
    
    </form>

  2. #2
    Join Date
    May 2006
    Location
    Somewhere behind your screen
    Posts
    1,633
    try this one

    Code:
    ... if (!reg.test(document.search_mini_form.q.value)) ...
    xxx: Guess Buddhist riddle: "What is the sound of one hand clapping?"
    yyy: facepalm

Thread Information

Users Browsing this Thread

There are currently 1 users browsing this thread. (0 members and 1 guests)

Posting Permissions

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



Recent Articles