validation - Tel Number visualization pattern - space after every second number -
i have editabe datatable. after user inserts tel number tel column input text box, , ok button clicked, need visualize following:
input 390239266655
output +39 02 39 26 66 55
so need put space after every second number, , putting + @ begining. how can ?
the following validation have:
<ui:define name="validation-tag"> <f:validateregex pattern="[0-9+]*" for="contactphonenumber" /> </ui:define>
we had write converter, here solution :
@facesconverter(value = "phoneconverter") public class phoneconverter implements converter { @override public object getasobject( facescontext context, uicomponent component, string value) { string stringtodisplay = null; // // if (value != null && !value.equals("") && value.startswith("+")) { // stringtodisplay = value.substring(1).trim(); // } return stringtodisplay; } @override public string getasstring( facescontext context, uicomponent component, object value) { string stringtodisplay = (string) value; string resulttodisplay = null; try { // if (!stringtodisplay.startswith("+")) { if (stringtodisplay != null && !stringtodisplay.equals("")) { resulttodisplay = getphonenumbformat(stringtodisplay); } } } catch (exception e) { log.error("phoneconverter replaceall failed!!! object:={} not found!!!", stringtodisplay, e); } return resulttodisplay; } private string getphonenumbformat( string phonenumber) { string resulttodisplay = null; if (!phonenumber.startswith("+")) { resulttodisplay = "+" + phonenumber.substring(0, 2).concat(" ") + phonenumber.substring(2).replaceall("(.{2})(?!$)", "$1 "); } else if (!phonenumber.substring(0, 3).startswith(" ")) { resulttodisplay = phonenumber.substring(0, 3).concat(" ") + phonenumber.substring(3).replaceall("(.{2})(?!$)", "$1 "); } return resulttodisplay; } }
Comments
Post a Comment