Warning: file_get_contents(/data/phpspider/zhask/data//catemap/9/javascript/462.json): failed to open stream: No such file or directory in /data/phpspider/zhask/libs/function.php on line 167

Warning: Invalid argument supplied for foreach() in /data/phpspider/zhask/libs/tag.function.php on line 1116

Notice: Undefined index: in /data/phpspider/zhask/libs/function.php on line 180

Warning: array_chunk() expects parameter 1 to be array, null given in /data/phpspider/zhask/libs/function.php on line 181
Javascript 验证特定格式_Javascript_Regex_Sapui5 - Fatal编程技术网

Javascript 验证特定格式

Javascript 验证特定格式,javascript,regex,sapui5,Javascript,Regex,Sapui5,我正在考虑验证我的程序的输入,该输入应具有以下格式:XXXXXXXX-Y X是数字 Y可以是数字或字母 -自动写入 这就是原因“编号”不适用于这种情况 您可以使用正则表达式来验证 var pattern = \[0-9]{8,}-[a-zA-Z]\; return pattern.test('12345678-A'); //will return true [0-9]{8,}-前8个字符的数字 -匹配- [a-zA-Z]-一个字符UPPERCase或小写您可以使用正则表达式进行验证 var

我正在考虑验证我的程序的输入,该输入应具有以下格式:XXXXXXXX-Y

  • X
    是数字
  • Y
    可以是数字或字母
  • -
    自动写入
这就是原因<代码>“编号”不适用于这种情况


您可以使用正则表达式来验证

var pattern = \[0-9]{8,}-[a-zA-Z]\;
return pattern.test('12345678-A'); //will return true
[0-9]{8,}
-前8个字符的数字
-
匹配-

[a-zA-Z]
-一个字符UPPERCase或小写

您可以使用正则表达式进行验证

var pattern = \[0-9]{8,}-[a-zA-Z]\;
return pattern.test('12345678-A'); //will return true
[0-9]{8,}
-前8个字符的数字
-
匹配-

[a-zA-Z]
-一个字符UPPERCase或小写

这是一个典型的使用案例。使用MaskInput无需验证(在前端),因为它甚至不允许键入无效字符,这也提高了用户体验

当然,您也可以继续使用
sap.m.Input
。在这种情况下,您可以将type
sap.ui.model.(odata.)type.String
与等待正则表达式的约束
search
一起使用。错误的输入不会传递到绑定模型

下面是一个演示,展示了这两个示例:

sap.ui.getCore().attachInit(()=>sap.ui.require([
“sap/ui/core/mvc/XMLView”,
“sap/ui/model/json/JSONModel”
],(XMLView,JSONModel)=>XMLView.create({
定义:`
`,
afterInit:function(){
const mySapMInput=this.byId(“sapMInput”);
setModel(新的JSONModel({
值:“”,
})“我的输入”);
sap.ui.getCore().getMessageManager().registerObject(mySapMInput,true);
},
})。然后(view=>view.placeAt(“内容”))

这是一个典型的应用程序用例。使用MaskInput无需验证(在前端),因为它甚至不允许键入无效字符,这也提高了用户体验

当然,您也可以继续使用
sap.m.Input
。在这种情况下,您可以将type
sap.ui.model.(odata.)type.String
与等待正则表达式的约束
search
一起使用。错误的输入不会传递到绑定模型

下面是一个演示,展示了这两个示例:

sap.ui.getCore().attachInit(()=>sap.ui.require([
“sap/ui/core/mvc/XMLView”,
“sap/ui/model/json/JSONModel”
],(XMLView,JSONModel)=>XMLView.create({
定义:`
`,
afterInit:function(){
const mySapMInput=this.byId(“sapMInput”);
setModel(新的JSONModel({
值:“”,
})“我的输入”);
sap.ui.getCore().getMessageManager().registerObject(mySapMInput,true);
},
})。然后(view=>view.placeAt(“内容”))