Skip to content

Instantly share code, notes, and snippets.

@smonff
Last active December 24, 2015 11:59
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save smonff/6794197 to your computer and use it in GitHub Desktop.
Save smonff/6794197 to your computer and use it in GitHub Desktop.
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