有人可以帮助我,我有一个序列号输入,并且我需要表达式regex来验证此输入[ex:11-22-33333]字符数max = 11,我添加了此模式,但没有工作
/path/to/project/SomeDataMapper.java:15: warning: Unmapped target property: "tlementDate".
SomeData toEntity(SomeDataDTO someDataDTO);
答案 0 :(得分:0)
由于您未指定regexp样式(java?bash?sed?python?php?),因此我在此处编写了最兼容的表达式:
"^[0-9]{2}-[0-9]{2}-[0-9]{5}$"
https://regex101.com/r/2xGgL1/1/
希望这会有所帮助
答案 1 :(得分:0)
"purchase-1_serialNumber": {
"extra_form_type": "text",
"options": {
"label": "Indiquez le n° de série:*",
"pattern": "^[0-9]{2}*-?[0-9]{2}*-?[0-9]{5}$",
"required": 1,
"disabled": "0",
"read_only": "0",
"attr": {
"title": "Ce numéro est composé de 9 chiffres séparés par 2 tirets (ex: 11-22-33333) que vous trouverez sur votre produit",
"class": "input_serie",
"placeholder": "N° de série*",
"minlength": 11,
"maxlength": 11
},
"label_attr": {
"class": "label_serie"
},
"mapped": 1
},
"constraints": [
{
"extra_form_constraint": "not_blank",
"options": {
"message": "Merci de renseigner le n° de série."
}
},
{
"extra_form_constraint": "regex",
"options": {
"pattern": "^[0-9]{2}*-?[0-9]{2}*-?[0-9]{5}$",
"match": true,
"message": "Merci de renseigner correctement le N° de série."
}
}
]
}
答案 2 :(得分:0)
鉴于您的原始模式为-?
,我猜测您可能想要的是既有痕迹又无痕迹的数字,因此我建议使用给定的正则表达式:
^((\d\d-){2}|(\d\d){2})\d{5}$
演示:
const regex = /^((\d\d-){2}|(\d\d){2})\d{5}$/;
const testStrings = [
'11-22-12345',
'112212345',
'1122-12345',
'11-2212345',
'1-12-12345',
'12-12-123456'
];
testStrings.forEach(s => console.log(`${s} - ${regex.test(s)}`));