0

我正在寻找一个可用于检查邮政地址字段值的

目前我使用这个表达式:

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

环境是:

,正则表达式存储在应用程序设计中的属性文件中。

<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>

是否有任何方法可以使为此目的的正则表达式更简单?

4

1 回答 1

0

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.

于 2012-08-16T10:25:16.400 回答