Forum Moderators: open
how can i have <input type="submit" value="submit" onclick="validate()"> where validate is a function that will make sure document.myform.mytext.value contains only letters (upper and lower case), numbers, and spaces and return false if not?
in php
<?
function validate($text){
if(ereg("^[A-Za-z0-9 ]+$",$text)) {
return true;
}else {
return false;
}
}
?>
i think i got that syntax right...thanks
<input type="submit" value="submit" onclick="validate([blue]this.form.mytext.value[/blue])"> then
function validate(value){
if(/^[A-Za-z0-9 ]+$/.test(value)) {
return true;
}else {
return false;
}
}
The real suggestion I'm making is to send the textarea's value with the
[blue]validate()[/blue] call. [blue]ereg[/blue] inside.