Last active
December 24, 2015 11:59
-
-
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
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
input { | |
height: 50px; | |
width: 90%; | |
} | |
#message { | |
color: red; | |
} |
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
<!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> |
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
$("#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