簡體   English   中英

提交 webflow 表單時返回 False 並帶有 Alert

[英]Return False with Alert upon webflow form submission

我正在嘗試編寫一個 JS 函數來阻止用戶提交個人電子郵件。 這是代碼。 當我刪除“警報”行時,用戶無法成功提交表單。 但是沒有提示他們輸入企業電子郵件的警報。

$("form").submit(function(){

// Get the email value from the input with an id="Email-2"
var email_addr = $('#Email-2').val();

// The regex to check it against
var re = '[a-zA-Z_\\.-]+@((hotmail)|(yahoo)|(gmail))\\.[a-z]{2,4}';

// Check if the email matches
if(email_addr.match(re)){
    // Email is on the filter list
    // Return false and don't submit the form, or do whatever
    window.alert("Enter Business Email");
    return false;
} else {
    // Email ok
    // Allow the form to be submitted
    return true;
}});

下面是發生錯誤的地方。 我是 Javascript 的新手,所以很可能是語法問題。

window.alert("Enter Business Email");
return false;

我找到了一個有效的解決方案,將代碼更改為以下內容:

$('#wf-form-Book-Demo-Form').submit(function(){ 
var email = $('#Email-2').val();
var reg = /^([\w-\.]+@(?!gmail.com)(?!yahoo.com)(?!hotmail.com)(?!yahoo.co.in)(?!aol.com)(?!abc.com)(?!xyz.com)(?!pqr.com)(?!rediffmail.com)(?!live.com)(?!outlook.com)(?!me.com)(?!msn.com)(?!ymail.com)([\w-]+\.)+[\w-]{2,4})?$/;
if (reg.test(email)){
return 0;
}
else{
alert('Please Enter Business Email Address');
return false;
}
});

暫無
暫無

聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.

 
粵ICP備18138465號  © 2020-2024 STACKOOM.COM