Wednesday, September 11, 2013

Regular Expression is not working for the string i'm submitting in Java

Regular Expression is not working for the string i'm submitting in Java

These are the strings that I should not allow in my address:
"PO BOX","P0 DRAWER","POSTOFFICE", " PO ", " BOX ",
"C/O","C.O."," ICO "," C/O "," C\0 ","C/0","P O BOX",
"P 0 BOX","P 0 B0X","P0 B0X","P0 BOX","P0BOX","P0B0X",
"POBX","P0BX","POBOX","P.0.","P.O","P O "," P 0 ",
"P.O.BOX","P.O.B","POB ","P0B","P 0 B","P O B",
" CARE ","IN CARE"," APO "," CPO "," UPO ", "GENDEL",
"GEN DEL", "GENDELIVERY","GEN DELIVERY","GENERALDEL",
"GENERAL DEL","GENERALDELIVERY","GENERAL DELIVERY"
I created regular expression: This expression validates only POBOx part –
please correct to not allow all the above strings in my address field
"([\\w\\s*\\W]*((P(O|OST)?.?\\s*((O(FF(ICE)?)?)?.?\\s*(B(IN|OX|.?))|B(IN|OX))+))[\\w\\s*\\W]*)+
|([\\w\\s*\\W]* (IN
\s*(CARE)?\\s*)|\s*[\\w\\s*\\W]*((.?(APO)?|.?(cPO)?|.?(uPO))?.?\s*)
[\\w\\s*\\W]*|([\\w\\s*\\W]*(GEN(ERAL)?)?.?\s*(DEL(IVERY)?)?.?\s*
[\\w\\s*\\W]*))";

No comments:

Post a Comment