我正在使用Angular 1.5表单构建器,我想在我的validation
文件中向input-date
添加json
:
{
"description": "managersList_birth_date",
"model": "birth_date",
"type": "input-date",
"name": "Bday",
"maxDate": "today",
"class": {
"main_part_class": "col-xs-12 col-sm-6 col-md-6",
"label_part_class": "",
"control_part_class": ""
},
"validation": {
"required": true,
"pattern": "/^(\d{2})\/(\d{2})\/(\d{4})$/" //error in json
}
}
1.我的json文件中存在错误 - Invalid escape character in string
。
2.这个正则表达式适用于form builder
?如果错误将得到解决。
答案 0 :(得分:1)
验证日期(日:1-31 /月:1-12 /年:1000 - 2999)
<强> JavaScript的:强>
const regex = /(^3[01]|^2[\d]{1})\/([0][0-9]|[1][012])\/([12]\d{3})/gm;
const str = `
22/09/1994 <-- GOOD
32/13/2000 <-- BAD
31/12/2004 <-- GOOD`;
let m;
while ((m = regex.exec(str)) !== null) {
// This is necessary to avoid infinite loops with zero-width matches
if (m.index === regex.lastIndex) {
regex.lastIndex++;
}
// The result can be accessed through the `m`-variable.
m.forEach((match, groupIndex) => {
console.log(`Found match, group ${groupIndex}: ${match}`);
});
}
<强> PHP:强>
$re = '/(^3[01]|^2[\d]{1})\/([0][0-9]|[1][012])\/([12]\d{3})/m';
$str = '22/09/1994 <-- GOOD
32/13/2000 <-- BAD
31/12/2004 <-- GOOD';
preg_match_all($re, $str, $matches);
// Print the entire match result
print_r($matches);
REGEXP :( 3组日/月/年)
(^3[01]|^2[\d]{1})\/([0][0-9]|[1][012])\/([12]\d{3})
<强>结果:强>
Full match 39-49 `31/12/2004`
Group 1. 39-41 `31`
Group 2. 42-44 `12`
Group 3. 45-49 `2004`
好/坏:
22/09/1994 <-- GOOD
32/13/2000 <-- BAD
31/12/2004 <-- GOOD
答案 1 :(得分:0)
所以我跳过了表单构建器验证(它有很多问题)并使用ng-pattern
:
ng-pattern='/^(0?[1-9]|[12][0-9]|3[01])\/(0?[1-9]|1[012])\/(19\d\d|20[12]\d)$/'
感谢。