Author: arunpatidar
Date: Sat Sep 23 12:35:27 2017
New Revision: 1809412
URL:
http://svn.apache.org/viewvc?rev=1809412&view=revLog:
IMPROVED: Updated phone validation method to validate phone for specific geo. (OFBIZ-9358)
> Thanks Renuka Srishti for your contribution.
Modified:
ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
Modified: ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java
URL:
http://svn.apache.org/viewvc/ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java?rev=1809412&r1=1809411&r2=1809412&view=diff==============================================================================
--- ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java (original)
+++ ofbiz/ofbiz-framework/trunk/framework/base/src/main/java/org/apache/ofbiz/base/util/UtilValidate.java Sat Sep 23 12:35:27 2017
@@ -29,6 +29,7 @@ import org.apache.ofbiz.entity.GenericEn
import org.apache.ofbiz.entity.GenericValue;
import org.apache.ofbiz.entity.util.EntityQuery;
import org.apache.ofbiz.entity.util.EntityUtilProperties;
+import org.apache.ofbiz.base.util.UtilMisc;
import com.google.i18n.phonenumbers.NumberParseException;
import com.google.i18n.phonenumbers.PhoneNumberUtil;
@@ -1391,13 +1392,17 @@ public final class UtilValidate {
}
public static boolean isValidPhoneNumber(String phoneNumber, Delegator delegator) {
+ String geoId = EntityUtilProperties.getPropertyValue("general", "country.geo.id.default", delegator);
+ return isValidPhoneNumber(phoneNumber, geoId, delegator);
+ }
+
+ public static boolean isValidPhoneNumber(String phoneNumber, String geoId, Delegator delegator) {
boolean isValid = false;
try {
+ GenericValue geo = EntityQuery.use(delegator).from("Geo").where("geoId", geoId).cache().queryOne();
PhoneNumberUtil phoneUtil = PhoneNumberUtil.getInstance();
- String defaultCountry = EntityUtilProperties.getPropertyValue("general", "country.geo.id.default", delegator);
- GenericValue defaultGeo = EntityQuery.use(delegator).from("Geo").where("geoId", defaultCountry).cache().queryOne();
- String defaultGeoCode = defaultGeo != null ? defaultGeo.getString("geoCode") : "US";
- PhoneNumber phNumber = phoneUtil.parse(phoneNumber, defaultGeoCode);
+ String geoCode = geo != null ? geo.getString("geoCode") : "US";
+ PhoneNumber phNumber = phoneUtil.parse(phoneNumber, geoCode);
if (phoneUtil.isValidNumber(phNumber) || phoneUtil.isPossibleNumber(phNumber)) {
isValid = true;
}
@@ -1406,4 +1411,4 @@ public final class UtilValidate {
}
return isValid;
}
-}
+}
\ No newline at end of file