aboutsummaryrefslogtreecommitdiff
path: root/bootstrap/comments/frontend/emailvalidator.js
blob: 7e7cf85f77a082f6fbd6a65088dee5a24a378ab5 (plain)
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
// Handles display of various e-mail warnings (emailvalidator.js)
HashOver.prototype.emailValidator = function (form, subscribe, type, permalink, isReply, isEdit)
{
	if (form.email === undefined) {
		return true;
	}

	// Whether the e-mail form is empty
	if (form.email.value === '') {
		// Return true if user unchecked the subscribe checkbox
		if (this.elements.get (subscribe, true).checked === false) {
			return true;
		}

		// If so, warn the user that they won't receive reply notifications
		// if (confirm (this.locale['no-email-warning']) === false) {
		// 	form.email.focus ();
		// 	return false;
		// }

	} else {
		// If not, check if the e-mail is valid
		if (this.regex.email.test (form.email.value) === false) {
			// Return true if user unchecked the subscribe checkbox
			if (this.elements.get (subscribe, true).checked === false) {
				form.email.value = '';
				return true;
			}

			// Get message from locales
			var message = this.locale['invalid-email'];

			// Show the message and focus the e-mail input
			this.messages.show (message, type, permalink, true, isReply, isEdit);
			form.email.focus ();

			return false;
		}
	}

	return true;
};