联系表单不接受非拉丁字符

时间:2016-01-27 23:17:19

标签: php validation contact-form

例如,当某人将希腊字符放在SEND的NAME字段中时,联系表单将返回错误报告。 那么,如何编辑我的联系表单以接受NAME和NAME中的非拉丁字符。 MESSAGE字段?

 function validation(){var contactname=document.forms["contactfrm"]["name"].value;var name_exp=/^[A-Za-z\s]+$/;if(contactname==''){swal("You forgot your name...", " ", "warning");document.forms["contactfrm"]["name"].focus();return false;}else if(!contactname.match(name_exp)){swal("Invalid name...", " ", "error");document.forms["contactfrm"]["name"].focus();return false;}var email=document.forms["contactfrm"]["email"].value; //var email_exp=/^[A-Za-z0-9\.-_\$]+@[A-Za-z]+\.[a-z]{2,4}$/;
var email_exp=/^\w+([-+.']\w+)*@\w+([-.]\w+)*\.\w+([-.]\w+)*$/;if(email==''){swal("You forgot to enter your email...", " ", "warning");document.forms["contactfrm"]["email"].focus();return false;} else if(!email.match(email_exp)){swal("Your email address is invalid...", " ", "error");document.forms["contactfrm"]["email"].focus();return false;}var message=document.forms["contactfrm"]["comments"].value; if(message==''){swal("No empty messages, please...", "warning");document.forms["contactfrm"]["comments"].focus();return false;}return true;}<?php if (isset($_GET["r"])){if($_GET["r"]=="1")echo('swal("Your message has been sent!", " ", "success");');else echo('swal("Your message failed to send...", " ", "error");');};?>

1 个答案:

答案 0 :(得分:2)

我拆开了你网站的js,找到并删除了这一行:

else if(!contactname.match(name_exp)){swal("Invalid name..."," ","error");

这将使名称成为任何东西(但不是空白,否则在其他地方检查)

或者找

name_exp=/^[A-Za-z\s]+$/

并替换为

name_exp=/^*+$/