Created
July 3, 2020 06:52
-
-
Save tks2shimizu/7c8fc04bb53824f352c0d684af776f7a to your computer and use it in GitHub Desktop.
メールアドレスの正規表現
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
console.log(valid_mail_address2('[email protected]')); | |
console.log(valid_mail_address2('[email protected]')); | |
console.log(valid_mail_address2('hogehoge.fugafuga.com')); | |
console.log(valid_mail_address2('hogehoge@fugafuga@com')); | |
console.log(valid_mail_address2('@fugafuga.com')); | |
console.log(valid_mail_address2('hogehoge@fugafuga')); | |
console.log(valid_mail_address2('[email protected]')); | |
function valid_mail_address2(mail) { | |
//正規表現 | |
var reg = /^[A-Za-z0-9]{1}[A-Za-z0-9_.-]*@{1}[A-Za-z0-9_.-]{1,}\.[A-Za-z0-9]{1,}$/; | |
return reg.test(mail); | |
} | |
function valid_mail_address(mail) { | |
var split_mail = mail.split('@'); | |
if (split_mail.length !== 2) { | |
return false; | |
} | |
if (split_mail[0].length === 0) { | |
return false; | |
} | |
var split_mail2 = split_mail[1].split('.'); | |
if (split_mail2.length <= 1) { | |
return false; | |
} | |
for (var i = 0; i < split_mail2.length; i++) { | |
if (split_mail2[i].length === 0) { | |
return false; | |
} | |
} | |
return true; | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment