I have a php form which I am trying to check. My code is shown below (only the piece which is questionable). This code works, however, what I want is the line I currently have commented off. If I comment off the first "if" statement (the one I don't want) I get an error saying "Object Expected". What am I doing wrong? Why will it work for the first if statement but not the second?
<script language="JavaScript" type="text/javascript">
function checkform (form1)
{if (form1.txtJobNo.value == "C"){
//{if (preg_match("/[A-a]{2,2}[0-9]{8,8}/", form1.$jobno)){
alert ("Please enter a valid job number");
return False;}
}
The problem is you are getting your javascript and php confused.
You are writing a javascript function there NOT php. preg_match() is php NOT javascript.
If you want to use regular expressions in javascript, this "should" work.
Code:
<script language="JavaScript" type="text/javascript">
function checkform (form1) {
var re = /[A-a]{2,2}[0-9]{8,8}/g;
if (form1.txtJobNo.match(re)) {
alert ("Please enter a valid job number");
return false;
}
}