I tried various solutions but it didn't work. Not that good with JavaScript especially with RegEx. Found this solution online, but couldn't modify it.
Basically I need to allow EDU domain in email field. I think it would be @ohio.edu or @ohio.edu.com or something like that. How can I say that if there isn't phrase "edu" after @, then don't allow the registration?
$(".single-memberpressproduct.postid-1945 .mepr-submit").click(function() {
validateEmail(jQuery("input#user_email1").val());
return false;
});
function validateEmail(email) {
var emailRegx = /b(?:(?![_.-])(?!.*[_.-]{2})[a-z0-9_.-]+(?<![_.-]))@(?:(?!-)(?!.*--)[a-z0-9-]+(?<!-).)*.edub/i;
if (emailRegx.test(email)) {
if (email.indexOf('@edu.com', email.length - '@edu.com'.length) !== -1) {
alert('Submission was successful.');
} else {
alert('Not a valid e-mail address @.');
}
} else {
alert('Not a valid e-mail address.');
}
}
<script src="https://cdnjs.cloudflare.com/ajax/libs/jquery/3.6.0/jquery.min.js"></script>
<form class="single-memberpressproduct postid-1945">
<input type="text" id="user_email1" value="" />
<input type="submit" class="mepr-submit" />
</form>
I ended up using different approach.
<script>
jQuery('.single-memberpressproduct.postid-1945 .mepr-submit').attr("disabled", "disabled");
var youtubeRegex = /edu/i;
jQuery('input#user_email1').keyup(function(){
jQuery(".single-memberpressproduct.postid-1945 .mepr-submit").attr("disabled", !youtubeRegex.test(this.value));
});
</script>