-
Notifications
You must be signed in to change notification settings - Fork 0
/
app.js
61 lines (54 loc) · 1.88 KB
/
app.js
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
$(document).ready(function() {
$("#form").submit(function(event) {
if (validate()) {
$.ajax({
url: "http://private-644da-frontend7.apiary-mock.com/aplication",
type: "post",
dataType: "json",
success: function(response) {
for (var i = 0; i < response.length; i++) {
var person = response[i];
if (person.edad > 25 && person.sexe.toLowerCase() == "femeni") {
console.log(person.nom);
};
}
},
error: function(jqXHR, textStatus, errorThrown) {
console.log(textStatus, errorThrown);
}
});
$("#ok").css("display", "block");
}
event.preventDefault();
});
function validateEmail(email) {
var re = /^(([^<>()[\]\\.,;:\s@\"]+(\.[^<>()[\]\\.,;:\s@\"]+)*)|(\".+\"))@((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/;
return re.test(email);
}
function validateName(name) {
var re = /^[A-Za-z ]+$/;
return re.test(name);
}
function validate() {
$("#result").text("");
var email = $("#email");
var name = $("#name");
var resultEmail = false;
var resultName = false;
if (validateEmail(email.val())) {
email.css("border-color", "");
resultEmail = true;
} else {
email.css("border-color", "red");
resultEmail = false;
}
if (validateName(name.val())) {
name.css("border-color", "");
resultName = true;
} else {
name.css("border-color", "red");
resultName = false;
}
return resultEmail && resultName;
}
});