akaballa123
Technical User
Hi,
I am a newbie to reg expressions but trying to create one to control what is typed in a form field. If certain characters are found, an alert box pops up a msg when the user clicks submit. I tried my code, but it is not working..im sure there is something wrong with the regex...plz check it out:
thanks!
I am a newbie to reg expressions but trying to create one to control what is typed in a form field. If certain characters are found, an alert box pops up a msg when the user clicks submit. I tried my code, but it is not working..im sure there is something wrong with the regex...plz check it out:
Code:
function nameRegex(str)
{
return /([a-zA-Z0-9])+!?><([a-zA-Z0-9_-])+/.test(str);
}
function checkName(str)
{
if(nameRegex(str) == false)
{
return false;
}
}
//Check the form for invalid or blank contents
function checkForm()
{
var myForm = window.document.trainingForm;
var ctName = myForm.tName;
if((ctName.value == '') || (checkName(ctName.value) == false))
{
alert('Please enter an appropriate course name');
ctName.focus();
return false;
}
}
thanks!