TypechoJoeTheme

技术小栈

统计
登录
用户名
密码

判断提交表单中邮箱格式及文章中含有某些特定单词及文章太短

2021-06-10
/
0 评论
/
225 阅读
/
正在检测是否收录...
06/10

html部分

<form id="formbox" action="/a.php" method="post">
                    <table border="0" width="100%" cellpadding="0" cellspacing="0">
                        <tbody>
                            <tr>
                                <td align="left"><input type="text" class="abilityContact-left-input" name="contacts" placeholder="* Name"></td>
                                <td align="center"><input type="text" class="abilityContact-left-input" name="mobile" placeholder="Phone"></td>
                                <td align="right"><input type="text" id="email" class="abilityContact-left-input" name="email" placeholder="* Email" onchange="checkEmail(this.value)"></td>
                            </tr>
                            <tr>
                                <td colspan="3">
                                    <textarea class="contactUsFont-textarea"  id="content" placeholder="* Message" name="content" onchange="checkNum(this.value)"></textarea>
                                </td>
                            </tr>
                            <input type="hidden" name="company" value="Google Ads source">
                            <tr>
                                <td colspan="3">
                                    <input type="submit" class="abilityContact-left-button" name="submit" id="submit" value="Send Message">
                                </td>
                            </tr>
                        </tbody>
                    </table>
                </form>

js部分

<script>
function checkEmail(str){
    var re = /^(\w-*\.*)+@(\w-?)+(\.\w{2,})+$/
    if(!re.test(str)){
       alert("Please enter the correct mailbox format");
       return false;
    }else{
        return true;
    }
  }
function checkNum(str){
 
    if(str.length<50){
      alert("Please enter more words so that we can better understand your needs");
      return false;
    }else{
       if(str.indexOf(' porn') != '-1') {
            alert("Please enter the requirements related to the website. We don't accept advertisements");
            return false;
       }else{
           return true;
       }
    }
}

 $("#submit").click(function(){
        var email=$("#email").val();
        if(checkEmail(email)){
          var content=$("#content").val();
        //   console.log(checkNum(content));
          if(checkNum(content)){
              return true;
          }else{
              return false;
          }
         
        }else{
            return false;
        }
        
    });
</script>
朗读
赞 · 0
版权属于:

技术小栈

本文链接:

https://inncms.com/111.html(转载时请注明本文出处及文章链接)

评论 (0)