我有一个使用正则表达式的表单,该正则表达式仅与空格一起验证字符,但是我有一个问题,这不能验证空字段。我的常规表达是这样的:
regex = /^\s*[a-zA-Z ]{2,30}$/;
答案 0 :(得分:0)
如果您还想验证一个空字段,则可以通过将// minimum 22.6 and maximum 41.8 are removed
[39.5, 34.8, 38.7, 25.4, 30.1, 33.6, 26.2, 27.3]
放在末尾来匹配整个模式,从而也匹配空字符串(即,匹配开头的位置)字符串的位置,紧随其后的是字符串末尾的位置):
Request.setSomething(2);// which is integer field
Integer num = Request.getSomething();
//while testing give the object i.e num
assertEquals(Request.getSomething(),num);