Announcement Announcement Module
Collapse
No announcement yet.
Regular expression for decimal numbers Page Title Module
Move Remove Collapse
X
Conversation Detail Module
Collapse
  • Filter
  • Time
  • Show
Clear All
new posts

  • Regular expression for decimal numbers

    Hi

    I need to have an iput text where user can insert only decimal numbers.

    I'm usign thei environment:
    • Spring 2.5.6
    • Spring webflow and Spring js 1.5.7

    I created this code in my jsp page:

    Code:
    <form:input path="gisExt.coordinataX" id="gisExt.coordinataX"/>
    <script type="text/javascript">
    /*<![CDATA[*/
    	Spring.addDecoration(new Spring.ElementDecoration({
    	elementId : "gisExt.coordinataX",
    	widgetType : "dijit.form.ValidationTextBox",
    	widgetAttrs : { required : false,
    	regExp : "^[0-9]+(|.\d*[0-9])+$", invalidMessage : "<spring:message code="invalidDecimalNumber" />" }}));
    	 /*]]>*/
    </script>
    <form:errors path="gisExt.coordinataX" cssClass="errore"></form:errors>
    I tried this simple java code:

    Code:
    String pattern = "^[0-9]+(|.\\d*[0-9])+$";
    Pattern patt = Pattern.compile(pattern);
    String[] valori = new String[]{"1234567.89056789","1234567.8","11223344.89","1234.8989", "1.89056789"};
    for (String valore : valori) {
    	
    	Matcher mat = patt.matcher(valore);
    	System.out.println("Checking: "+valore+"  mat.matches()--> "+mat.matches());
    }
    This is my test output:
    Checking: 1234567.89056789 mat.matches()--> true
    Checking: 1234567.8 mat.matches()--> true
    Checking: 11223344.89 mat.matches()--> true
    Checking: 1234.8989 mat.matches()--> true
    Checking: 1.89056789 mat.matches()--> true
    If i try the same numbers in my browser for all the values except the first one i got the error that the regexpr is not verified.

    Do u have any ideas? How can i solve it?

    Regards,
    Angelo.
    Last edited by craig1980; Mar 16th, 2010, 06:07 AM.
Working...
X