邮箱/垃圾箱验证 [英] post box/bin validation
本文介绍了邮箱/垃圾箱验证的处理方法,对大家解决问题具有一定的参考价值,需要的朋友们下面随着小编来一起学习吧!
问题描述
我需要为注册页面中的地址字段提供邮政信箱验证.现在我们在 jquery 中有一个正则表达式验证,它有一些限制,如下所示:
I need to provide the P.O Box validation for the address Fields in the registration page. Now we have a regex validation in jquery which has some limitations as follows:
- 如果给出地址 polo Rd,它会在 polo 中标识po"并警告错误消息.
因此,我们应该构建一个新的验证,该验证不应接受带有值的地址行:
So, we should frame a new validation which should not accept address lines with the values:
"PO BOX"
,"PO BIN"
,"BIN"
,"PO BOX"
,"PO BIN"
,"PO"
,"PO"
- 上述值在任何情况下都可以
- 还应找到并验证上述单词之前、之间和之后的空格.例如:
" P O 1234 "
应验证并警告错误消息. - 但是
"Polo Rd"
、"Robin Rd"
、"testbintest"
应该被接受为两个地址行中的有效地址.
"PO BOX"
,"PO BIN"
,"BIN"
,"P.O BOX"
,"P.O BIN"
,"P.O"
,"PO"
- the above values can be in any case
- spaces before, in between and after the above words should also be found and validated. For example:
" P O 1234 "
should be validated and alert error message. - But
"Polo Rd"
,"Robin Rd"
,"testbintest"
should be accepted as valid address in both the address lines.
现在在 jquery 验证中的代码是:
The code right now in jquery validation is:
jQuery.validator.addMethod("nopobox", function(value, element) {
return this.optional(element) || ! /(P(OST)?\.?\s*O(FF(ICE)?)?\.?\s*(?<!(BOX)|(BIN)))|(^[^0-9]*((P(OST)?\.?\s*O(FF(ICE)?)?\.?)|(?<!(BOX)|(BIN))))/i.test(value);
}, "");
推荐答案
/**
* The below are the possible combinations P.O.BOX, PO.BOX, P O BOX, P O B O
* X, POBOX, PO BOX, P.O.B.O.X
*
* @param input
* @return true if the input value = pobox else false
*/
public static boolean checkPoBox(String input) {
boolean poBox = false;
String inputVal = input;
try {
if (input.length() > 4) {
inputVal = inputVal.replace(".", "").replace(" ", "")
.toLowerCase();
if (inputVal.contains("pobox")
|| inputVal.equalsIgnoreCase("pobox")) {
poBox = true;
}
}
} catch (Exception e) {
log.debug("Exception from checkPoBox");
}
return poBox;
}
这篇关于邮箱/垃圾箱验证的文章就介绍到这了,希望我们推荐的答案对大家有所帮助,也希望大家多多支持IT屋!
查看全文