Validate Data Entry Has Numbers and Letters Both

[Total: 0    Average: 0/5]

This shows how to ensure that both letters and numbers are used in the text box.

Body Code:

<form>
<input type=text name=t1>
<input type=button value="validate" onclick=doIt(this.form)>
</form>
<script>
function doIt(form)
{
  var SHOW_ALERT = true; // make be false to supress the alerts.
  var _alpha = form.t1.value.search(/[a-z]|[A-Z]/);
  var _numer = form.t1.value.search(/d/);
  if (_alpha==-1)
  {
    if (SHOW_ALERT) alert("No characters!n"+_alpha);
	return false;
  }
  if (_numer==-1)
  {
    if (SHOW_ALERT) alert("No numbers!n"+_numer);
	return false;
  }
  if (SHOW_ALERT) alert("Data Validated!");
  return true;
}
</script>

Times Viewed: 0

Leave a Reply

Your email address will not be published. Required fields are marked *