como puedo combertir este codigo jQuery a PHP
Publicado por javier (5 intervenciones) el 08/05/2020 20:55:01
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
jQuery(function($){
function validateIdentificationNumber(number) {
// Be sure to have something to test
if (!number) {
return false;
}
// Only take the first 11 characters
number = number.substr(0, 11);
// Test if we have well a 11-digit string
if (!/\d{11}/.test(number)) {
return false;
}
// Numbers we're going to check against
var to_control = number.substr(0, 9);
// Verification number
var control = number.substr(9, 2);
// Date parsing
var date = number.substr(0, 6);
var date_year = parseInt(date.substr(0, 2), 10);
var date_month = parseInt(date.substr(2, 2), 10);
var date_day = parseInt(date.substr(4, 2), 10);
var today_year = parseInt(new Date().getFullYear().toString().substr(2, 2), 10);
// Simple date check
if (date_month < 1 || date_month > 12 || date_day < 1 || date_day > 31) {
return false;
}
// Add '2' before if date after 1st Jan 2000
if (date_year < today_year) {
to_control = '2' + to_control.toString();
}
// Modulo calculation
to_control = parseInt(to_control, 10);
var modulo = 97 - (to_control % 97);
modulo = Math.floor(modulo);
modulo = modulo < 10 ? '0' + modulo : '' + modulo;
// Final test
return control === modulo;
}
$('#id_validator').submit(function(event){
event.preventDefault();
var input = $('#id_number').val();
var valid = validateIdentificationNumber(input);
$('#validity').text(valid ? 'valid' : 'invalid');
});
})
Valora esta pregunta


0