• Status: Solved
  • Priority: Medium
  • Security: Public
  • Views: 254
  • Last Modified:

Numbers and A to Z in form

One little thing, why is this wrong if i also want a field for a-z, A-Z and 0-9.

if (/^[a-zA-Z0-9]*$/.test(document.mcform.frmParticipantPassword.value)) {

alert("Only number is allowed for quantity!");
document.mcform.frmParticipantPassword.focus();
return false;

it don't seems to work
<script language="JavaScript" type="text/javascript">
<!--
function MCValidation()
{


if (document.mcform.frmParticipantPassword.value == "") {

alert("Password is required!");
document.mcform.frmParticipantPassword.focus();
return false;

}

if (document.mcform.frmParticipantPassword.value.length < 6) {

alert("Password must contain at least six characters!");
document.mcform.frmParticipantPassword.focus();
return false;

}
if (/^[a-zA-Z0-9]*$/.test(document.mcform.frmParticipantPassword.value)) {

alert("Only number and a-z is allowed!");
document.mcform.frmParticipantPassword.focus();
return false;

} 

return true;

}

// -->
</script>

Open in new window

0
MickeC
Asked:
MickeC
1 Solution
 
leakim971PluritechnicianCommented:
add the not operator << ! >> 

if (!/^[a-zA-Z0-9]*$/.test(document.mcform.frmParticipantPassword.value)) {
0

Featured Post

Never miss a deadline with monday.com

The revolutionary project management tool is here!   Plan visually with a single glance and make sure your projects get done.

Tackle projects and never again get stuck behind a technical roadblock.
Join Now