我正在尝试使用正则表达式验证 PHP 页面输入,但我在这里是全新的,需要一些帮助
<script>
function addplaces()
{
valid=true;
placename=document.getElementById("placename").value;
city=document.getElementById("city").value;
province=document.getElementById("province").value;
country=document.getElementById("country").value;
category=document.getElementById("category").value;
placepicture=document.getElementById("placepicture").value;
descp=document.getElementById("descp").value;
if(placename=="" || preg_match("^[A-Z]'?[- a-zA-Z]( [a-zA-Z])*$", placename))
{
alert("Please Enter Place Name");
document.getElementById("placename").focus();
valid=false;
}
else if(city=="")
{
alert("Please Enter City Name");
document.getElementById("city").focus();
valid=false;
}
else if(province=="")
{
alert("Please Enter province Name");
document.getElementById("province").focus();
valid=false;
}
else if(country=="")
{
alert("Please Enter country Name");
document.getElementById("country").focus();
valid=false;
}
else if(category=="")
{
alert("Please Enter category Name");
document.getElementById("category").focus();
valid=false;
}
else if(placepicture=="")
{
alert("Please Enter place picture");
document.getElementById("placepicture").focus();
valid=false;
}
else if(descp=="")
{
alert("Please Enter Description");
document.getElementById("descp").focus();
valid=false;
}
return valid;
}
</script>
我尝试使用preg_match();
但它不起作用,请让我知道我在哪里犯了错误。