Skip to content

Instantly share code, notes, and snippets.

@smonff smonff/jsbin.UkIFuRi.css
Last active Dec 24, 2015

Embed
What would you like to do?
Search a textarea for a mail address and disable the sform submission button if found
input {
height: 50px;
width: 90%;
}
#message {
color: red;
}
<!DOCTYPE html>
<html>
<head>
<script class="jsbin" src="http://ajax.googleapis.com/ajax/libs/jquery/1/jquery.min.js"></script>
<meta charset=utf-8 />
<title>JS Bin</title>
<!--[if IE]>
<script src="http://html5shiv.googlecode.com/svn/trunk/html5.js"></script>
<![endif]-->
<style>
article, aside, figure, footer, header, hgroup,
menu, nav, section { display: block; }
</style>
</head>
<body>
<fieldset>
<input type="textarea" placeholder="Ici essaie de mettre une adresse mail"/>
<span id="message">Interdit !</span>
<input id="validate" type="submit" value="Envoyer la purée" />
</fieldset>
</body>
</html>
$("#message").hide();
$('input[type=textarea]').bind('input propertychange', function() {
$("#message").hide();
var checklength = $(this).val().length;
if(checklength > 3){
var text_area_content = $(this).val();
console.log(text_area_content);
var email_regex = /[A-Za-z0-9._%+-]+@[A-Za-z0-9.-]+\.[A-Za-z]{2,4}/i;
console.log($(this).val());
if(text_area_content.match(email_regex)) {
$('#validate').attr("disabled", "disabled");
$("#message").show();
console.log("!!!!! MAIL DÉTECTÉ !!!!!");
} else {
$('#validate').removeAttr("disabled");
}
}
});
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.