Warning: file_get_contents(/data/phpspider/zhask/data//catemap/2/jquery/77.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Php Jquery表单验证名称…它必须包含所有字符。。。帮帮我_Php_Jquery_Html - Fatal编程技术网

Php Jquery表单验证名称…它必须包含所有字符。。。帮帮我

Php Jquery表单验证名称…它必须包含所有字符。。。帮帮我,php,jquery,html,Php,Jquery,Html,name是name id 提交是提交id 帮助我转换代码以检查它是否包含所有字符(无数字和特殊字符) $(文档).ready(函数(){ $('.form_error').hide(); $(“#提交”)。单击(函数(){ var name=$('#name').val(); 如果(名称=“”){ $('#name').next().show(); 返回false; }否则{ 返回true; } //ajax调用php页面 $.post(“send.php”, $(“#contactf

name是name id
提交是提交id

帮助我转换代码以检查它是否包含所有字符(无数字和特殊字符)


$(文档).ready(函数(){
$('.form_error').hide();
$(“#提交”)。单击(函数(){
var name=$('#name').val();
如果(名称=“”){
$('#name').next().show();
返回false;
}否则{
返回true;
}    
//ajax调用php页面
$.post(“send.php”,
$(“#contactform”).serialize(),函数(响应){
$(“#contactform”).fadeOut('slow',function(){
});
});
返回false;
});
});
姓名:
请输入您的有效姓名


name是name id
提交是提交id

帮助我转换代码以检查它是否包含所有字符(无数字和特殊字符)

替代方法:

$(函数(){
$('#name').keydown(函数(e){
if(e.shiftKey | | e.ctrlKey | | e.altKey){
e、 预防默认值();
}否则{
var key=e.keyCode;

如果(!((key==8)| |(key==32)| |(key==46)| |(key>=35&&key=65&&key)还不起作用:(你建议的上述代码放在哪里?谢谢。)代码应该可以工作。如果文本框中键入了非字母,则第一个代码段警告您只能输入字母,第二个代码段不允许您在文本框中键入非字母。您可以根据自己的情况使用两个代码中的任意一个。您可以将代码放在任意位置。
<html>
<head>
<script src="https://ajax.googleapis.com/ajax/libs/jquery/1.12.0/jquery.min.js"></script>
<script type="text/javascript">
   $(document).ready(function() {                             
       $('.form_error').hide();
       $('#submit').click(function(){
        var name = $('#name').val();
        if(name== '') {
           $('#name').next().show();
           return false;
       } else {
           return true;
       }    

//ajax call php page
 $.post("send.php", 
       $("#contactform").serialize(),  function(response) {
            $('#contactform').fadeOut('slow',function(){
              });
          });
          return false;
      });
 });

</script>       
    <form action="" method="post" id="contactform">
 Name: <input name="name" id="name" type="text" 
 placeholder="Please enter your name" class="contact-input">
  <span class="form_error"> Please enter your valid name</span>
  <br><br>                                      
<input type="submit" class="contactform-buttons" id="submit"value="Send" />

</form>                             
</html>           
$(function() {       
     $('#name').keypress(function (e) {
                    var regex = new RegExp("^[a-zA-Z]+$");
                    var str = String.fromCharCode(!e.charCode ? e.which : e.charCode);
                    if (regex.test(str)) {
                        return true;
                    }
                    else
                    {
                      e.preventDefault();
                      alert('Please enter only alphabet');
                      return false;
                    }
                });
});
    $(function() {
            $('#name').keydown(function(e) {
              if (e.shiftKey || e.ctrlKey || e.altKey) {
                e.preventDefault();
              } else {
                var key = e.keyCode;
                if (!((key == 8) || (key == 32) || (key == 46) || (key >= 35 && key <= 40) || (key >= 65 && key <= 90))) {
                  e.preventDefault();
                }
              }
            });
          });