Here we use an "mailgun_validator.js" for email validation .
//Html Code
<form>
<div>
<label for="email">Email address</label><br>
<input type="email" name="email" id="email">
<div id="status"></div>
</div>
<div>
<button type="submit" id="validate_submit">Validate</button>
</div>
</form>
//java script
<script src="mailgun_validator.js"></script>
// document ready
$(function() {
// capture all enter and do nothing
$('#email').keypress(function(e) {
if(e.which == 13) {
$('#email').trigger('focusout');
return false;
}
});
// capture clicks on validate and do nothing
$("#validate_submit").click(function() {
return false;
});
// attach jquery plugin to validate address
$('#email').mailgun_validator({
api_key: 'MAILGUN_PUBKEY', // replace this with your Mailgun public API key
in_progress: validation_in_progress,
success: validation_success,
error: validation_error,
});
});
// if email successfull validated
function validation_success(data) {
$('#status').html(get_suggestion_str(data['is_valid'], data['did_you_mean']));
}
// if email is invalid
function validation_error(error_message) {
$('#status').html(error_message);
}
// suggest a valid email
function get_suggestion_str(is_valid, alternate) {
if (alternate) {
return '<span class="warning">Did you mean <em>' + alternate + '</em>?</span>';
} else if (is_valid) {
return '<span class="success">Address is valid.</span>';
} else {
return '<span class="error">Address is invalid.</span>';
}
}
MAILGUN_PUBKEY: pubkey-5ogiflzbnjrljiky49qxsiozqef5jxp7
Linkedin Profile Here is creative java developer.having many creative concept to solve spring complexity
Wednesday, July 16, 2014
email validation
Subscribe to:
Post Comments (Atom)
No comments:
Post a Comment