![](/img/trans.png)
[英]How to display email inbox for Gmail, Yahoo, Hotmail, AOL using Javascript?
[英]How to check if email is not a gmail or hotmail
嗨,我是 javascript 的新手,我正在嘗試檢查我網站上的新注冊用戶是否沒有使用 gmail / hotmail / 或雅虎
這是我試圖檢查郵件是否不是 gmail / hotmail / yahoo。 但是如果用戶使用其中之一,我仍然會收到錯誤和控制台日志:
不使用 gmail 的示例仍然會收到錯誤和控制台日志
var testMail = 'testmail@fakemail.com'; var check_email = '[a-zA-Z0-9]{0,}([.]?[a-zA-Z0-9]{1,})[@](gmail.com|hotmail.com|yahoo.com)'; if (.testMail.check_email) { //errors:push({msg; "You can't use that email to register"}). console.log("You can't use that email to register") // using console.log for testing }
使用 gmail / hotmail / yahoo 的示例:
var testMail = 'testmail@gmail.com'; var check_email = '[a-zA-Z0-9]{0,}([.]?[a-zA-Z0-9]{1,})[@](gmail.com|hotmail.com|yahoo.com)'; if (.testMail.check_email) { //errors:push({msg; "You can't use that email to register"}). console.log("You can't use that email to register") // using console.log for testing }
您在check_email
中有一個 Regex 模式,但您沒有在任何地方使用它。 嘗試這樣的事情:
var testMail = 'testmail@fakemail.com'; var check_email = '[a-zA-Z0-9]{0,}([.]?[a-zA-Z0-9]{1,})[@](gmail.com|hotmail.com|yahoo.com)'; var patt = new RegExp(check_email); var result = patt.test(testMail); if (.result) { //errors:push({msg; "You can't use that email to register"}). console.log("You can't use that email to register") // using console.log for testing }
您可以使用 search() 方法並將check_email設置為參數。
var testMail = 'testmail@fakemail.com';
var check_email = '[a-zA-Z0-9]{0,}([.]?[a-zA-Z0-9]{1,})[@](gmail.com|hotmail.com|yahoo.com)';
if (!testMail.search(check_email)) {
//errors.push({msg: "You can't use that email to register"});
console.log("You can't use that email to register") // using console.log for testing
}
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.