Jump to content

Javascript Validation in search field NOT NULL & 3 Characters Minimum


yandoo

Recommended Posts

Hi,

 

Im currently adding some validation to my search field. So far i have added validation that dislpays a mesage when the user leaves the search field empty.

 

The following code is how i have done this:


<script type="text/javascript">
function validate_required(field,alerttxt)
{
with (field)
{
if (value==null||value=="")
  {alert(alerttxt);return false}
else {return true}
}
}

function validate_form(thisform)
{
with (thisform)
{
if (validate_required(finda,"Email must be filled out!")==false)
  {finda.focus();return false}
}
}
</script>

<form name="search" method="get" action="search_client_details.php"
		onsubmit="return validate_form(this)">
              <input type="text" name="finda"/> 
              <span class="style10">in</span>
              <Select NAME="field">
                <Option VALUE="Client">Client Name</option>
                <Option VALUE="DepartmentCode">Department</option>
              </Select>
              <input type="hidden" name="searching" value="yes" />
              <input type="submit" name="search" value="Search" />
		  </form>

 

I would like to make it so that the user can not only leave the search field empty but also the user MUST use at least 3 characters when searching.  If the user was searching for a name in the database they would need to input the first three letters into the search field.........

 

E.G. If they are searching for a record name called Thomas (they would as a minimum) need to enter the first 3 letters THO. Is this possible please?????

 

If so how do i do it????

 

Any help is greatly appreciated

 

Thanks

 

Tom

 

:)

Link to comment
Share on other sites

Post in the correct forum, this is PHP not Javascript.

 

uuuh... javascript not php*

 

Eh what I meant was this is the PHP Forum not the Javascript forum.

 

EDIT: Just noticed it got moved, oh well. I will look like a jackass.

Link to comment
Share on other sites

Post in the correct forum, this is PHP not Javascript.

 

uuuh... javascript not php*

 

Eh what I meant was this is the PHP Forum not the Javascript forum.

 

EDIT: Just noticed it got moved, oh well. I will look like a jackass.

 

lol... dont worry... i had impecable timing too ;)

Link to comment
Share on other sites

This thread is more than a year old. Please don't revive it unless you have something important to add.

Join the conversation

You can post now and register later. If you have an account, sign in now to post with your account.

Guest
Reply to this topic...

×   Pasted as rich text.   Restore formatting

  Only 75 emoji are allowed.

×   Your link has been automatically embedded.   Display as a link instead

×   Your previous content has been restored.   Clear editor

×   You cannot paste images directly. Upload or insert images from URL.

×
×
  • Create New...

Important Information

We have placed cookies on your device to help make this website better. You can adjust your cookie settings, otherwise we'll assume you're okay to continue.