forked from chalkers/validEmail
-
Notifications
You must be signed in to change notification settings - Fork 0
Expand file tree
/
Copy pathvalidEmail.js
More file actions
32 lines (25 loc) · 840 Bytes
/
validEmail.js
File metadata and controls
32 lines (25 loc) · 840 Bytes
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
(function( $ ) {
$.fn.validEmail = function(options) {
options = options || {};
var on = options.on;
var success = options.success || (function(){});
var failure = options.failure || (function(){});
var testInitially = options.testInitially || false;
var $input = $(this);
function check($input) {
if($input.is("input,textarea")) {
var emailRegExp = /^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,4}$/i;
return emailRegExp.test($input.val());
} else {
return false;
}
}
function applyCode($input) {
check($input) ? success.call($input.get(0)) : failure.call($input.get(0));
}
if (typeof on === "string")
$input.bind(on, function() { applyCode($(this)); });
if (testInitially) $input.each(function() { applyCode($(this)); });
return check($input);
};
})( jQuery );