Search code examples
regexfieldtextfieldxpageslotus

Regular expression for checking postal address field value


I am looking for a which can be used to check a postal address field value, with minimum length of 10, containing numbers, and characters as well:

Currently I use this expression:

`\\[a-zA-Z]|\d|.|\s{10,}`

The environment is:

, and the regular expression is stored in properties file within the application design.

<xp:inputText id="address" dojoType="dijit.form.ValidationTextBox" value="#{complaintDocument.address}">
    <xp:this.dojoAttributes>
    <xp:dojoAttribute name="promptMessage">
            <xp:this.value><![CDATA[${javascript:clientData['address']}]]></xp:this.value>
        </xp:dojoAttribute>                     
        <xp:dojoAttribute name="placeHolder">
            <xp:this.value><![CDATA[${javascript:common['textValueMinimumTenCharacters']}]]></xp:this.value>
        </xp:dojoAttribute>                                         
        <xp:dojoAttribute name="trim" value="true">
        </xp:dojoAttribute>
        <xp:dojoAttribute name="regExp">
            <xp:this.value><![CDATA[#{javascript:regExp['minimumTenCharacters']}]]></xp:this.value>
        </xp:dojoAttribute>
    </xp:this.dojoAttributes>
</xp:inputText>

Is there any wat to make the regular expression for this purpose more simple?


Solution

  • I dont thinkt that your regex can be any simpler. Maybe you could use

    .{10} > any character, max 10 length


    If you want to check if a zipcode is valid you can make a java class that is used to check if the zipcode that was filled in is correct. This class can be a stored in the application scope

        <faces-config>
        <managed-bean-name>
        yourzipcodeclass</managed-bean-name>
        <managed-bean-scope>
        application</managed-bean-scope>
    <managed-bean-class>yourclass</managed-bean-class>
    </faces-config>
    
        </faces-config>
    

    Anyways When you want to check if a value is a valid zipcode you should add a method to this class isValidZipCode(String code, String country)

    in this method you check depending on the country you have given if the zipcode is correct. How you check it is up to you. You can use a regex for every country or you can use a webservice, or a lookup in a database etc.

    You can use this method in a custom validator.