forked from stevenmills/bootstrapvalidator
-
Notifications
You must be signed in to change notification settings - Fork 0
/
Copy pathmailgun.html
105 lines (100 loc) · 4.23 KB
/
mailgun.html
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
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
83
84
85
86
87
88
89
90
91
92
93
94
95
96
97
98
99
100
101
102
103
104
105
<!DOCTYPE html>
<html>
<head>
<title>FormValidation demo</title>
<link rel="stylesheet" href="../vendor/bootstrap/css/bootstrap.css"/>
<link rel="stylesheet" href="../dist/css/formValidation.css"/>
<script type="text/javascript" src="../vendor/jquery/jquery.min.js"></script>
<script type="text/javascript" src="../vendor/bootstrap/js/bootstrap.min.js"></script>
<script type="text/javascript" src="../dist/js/formValidation.js"></script>
<script type="text/javascript" src="../dist/js/framework/bootstrap.js"></script>
</head>
<body>
<div class="container">
<div class="row">
<div class="col-xs-8 col-xs-offset-2">
<div class="page-header">
<h1>Using MailGun API to validate email address</h1>
</div>
<form id="defaultForm" method="post" class="form-horizontal" action="target.php">
<div class="form-group">
<label class="col-xs-3 control-label">Email address</label>
<div class="col-xs-6">
<input type="text" class="form-control" name="email" />
</div>
</div>
<div class="form-group">
<div class="col-xs-9 col-xs-offset-3">
<button type="submit" class="btn btn-primary">Submit</button>
</div>
</div>
</form>
</div>
</div>
</div>
<script type="text/javascript">
$(document).ready(function() {
$('#defaultForm')
.formValidation({
icon: {
valid: 'glyphicon glyphicon-ok',
invalid: 'glyphicon glyphicon-remove',
validating: 'glyphicon glyphicon-refresh'
},
fields: {
email: {
verbose: false,
validators: {
notEmpty: {
message: 'The email address is required and can\'t be empty'
},
emailAddress: {
message: 'The input is not a valid email address'
},
stringLength: {
max: 512,
message: 'Cannot exceed 512 characters'
},
remote: {
type: 'GET',
url: 'https://api.mailgun.net/v2/address/validate?callback=?',
crossDomain: true,
name: 'address',
data: {
api_key: 'pubkey-83a6-sl6j2m3daneyobi87b3-ksx3q29'
},
dataType: 'jsonp',
validKey: 'is_valid',
message: 'The email is not valid'
}
}
}
}
})
.on('success.validator.fv', function(e, data) {
if (data.field === 'email' && data.validator === 'remote') {
var response = data.result; // response is the result returned by MailGun API
if (response.did_you_mean) {
// Update the message
data.element // The field element
.data('fv.messages') // The message container
.find('[data-fv-validator="remote"][data-fv-for="email"]')
.html('Did you mean ' + response.did_you_mean + '?')
.show();
}
}
})
.on('err.validator.fv', function(e, data) {
if (data.field === 'email' && data.validator === 'remote') {
// We need to reset the error message
data.element // The field element
.data('fv.messages') // The message container
.find('[data-fv-validator="remote"][data-fv-for="email"]')
.html('The email is not valid')
.show();
}
});
});
</script>
</body>
</html>