Last active
June 6, 2025 09:47
-
-
Save tranchausky/5a2264d024a2e5bb2fa52ac8b4ac185f to your computer and use it in GitHub Desktop.
https://help.xmatters.com/ondemand/trial/valid_email_format.htm script validate email can 255 chracter https://html.chaucc.top/?html=https://gist.githubusercontent.com/tranchausky/5a2264d024a2e5bb2fa52ac8b4ac185f/raw/462e3f12e5899979badd4846efc24592a28813d9/demo-validate-email-script.html
This file contains hidden or 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
<!DOCTYPE html> | |
<html lang="en"> | |
<head> | |
<meta charset="UTF-8" /> | |
<title>Email Validation Strict Demo</title> | |
<style> | |
input { | |
width: 320px; | |
padding: 8px; | |
font-size: 16px; | |
} | |
.valid { | |
border: 2px solid green; | |
} | |
.invalid { | |
border: 2px solid red; | |
} | |
#message { | |
font-size: 14px; | |
margin-top: 5px; | |
} | |
#message.valid { | |
color: green; | |
} | |
#message.invalid { | |
color: red; | |
} | |
</style> | |
</head> | |
<body> | |
<h2>Strict Email Validation</h2> | |
<input type="text" id="emailInput" placeholder="Enter your email" /> | |
<div id="message"></div> | |
<script> | |
function isValidEmail(email) { | |
const emailRegex = /^[a-zA-Z0-9](\.?[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-])*[a-zA-Z0-9]@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/; | |
if (email.includes('..')) return false; | |
if (email.indexOf('#') !== -1) return false; | |
return emailRegex.test(email); | |
} | |
const input = document.getElementById('emailInput'); | |
const message = document.getElementById('message'); | |
input.addEventListener('blur', () => { | |
const val = input.value.trim(); | |
if (!val) { | |
input.className = ''; | |
message.textContent = ''; | |
return; | |
} | |
if (isValidEmail(val)) { | |
input.className = 'valid'; | |
message.textContent = 'Valid email address'; | |
message.className = 'valid'; | |
} else { | |
input.className = 'invalid'; | |
message.textContent = 'Invalid email address'; | |
message.className = 'invalid'; | |
} | |
}); | |
</script> | |
</body> | |
</html> |
This file contains hidden or 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
https://html.chaucc.top/?html=https://gist.githubusercontent.com/tranchausky/5a2264d024a2e5bb2fa52ac8b4ac185f/raw/462e3f12e5899979badd4846efc24592a28813d9/demo-validate-email-script.html |
This file contains hidden or 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
$.validator.methods.emailnew = function (email, element) { | |
const emailRegex = /^[a-zA-Z0-9](\.?[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-])*[a-zA-Z0-9]@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/; | |
if (email.includes('..')) return false; | |
if (email.indexOf('#') !== -1) return false; | |
return emailRegex.test(email); | |
} |
This file contains hidden or 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(isValidEmail("[email protected]")); // false (TLD 1 char) | |
console.log(isValidEmail("abc.def@mail#archive.com"));// false (# in domain) | |
console.log(isValidEmail("abc.def@mail")); // false (no TLD) | |
console.log(isValidEmail("[email protected]")); // false (double dot domain) | |
console.log(isValidEmail("[email protected]")); // false (local ends with '-') | |
console.log(isValidEmail("[email protected]")); // false (double dot local) | |
console.log(isValidEmail("[email protected]")); // false (local starts with '.') | |
console.log(isValidEmail("abc#[email protected]")); // false (# in local) | |
console.log(isValidEmail("[email protected]")); // true (valid) | |
console.log(isValidEmail("[email protected]")); // true (valid) | |
gfdgggggggggggggggggggggggggggggggggrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrrryyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyyywwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwwffffffffffffffffffffffffff@ |
This file contains hidden or 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
function isValidEmail(email) { | |
// Basic regex with stricter local and domain rules: | |
// Local part: starts and ends with alphanumeric, no consecutive dots or special chars at ends | |
// Domain: labels with letters, digits, hyphens, separated by single dots, TLD >= 2 letters | |
const emailRegex = /^[a-zA-Z0-9](\.?[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-])*[a-zA-Z0-9]@([a-zA-Z0-9-]+\.)+[a-zA-Z]{2,}$/; | |
// Disallow consecutive dots anywhere | |
if (email.includes('..')) return false; | |
// Disallow invalid characters (only allow listed in regex) | |
// Extra check for # in email | |
if (email.indexOf('#') !== -1) return false; | |
// Validate with regex | |
return emailRegex.test(email); | |
} |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment