1 Reply Latest reply on Feb 14, 2012 7:48 AM by Jorge Campos

    Regex/star caracter not working with rich:validator

    jonathan.man Newbie

      Regex/star caracter not working with rich:validator

       

      Hi everyone.

       

      I'm trying to get rich:validator working with the f:validateRegex on the "blur" event.

       

      I get the following regex working fine : [1-9]+

      Whenever I put letters in the input field, the "blur" event show an error message.

       

      However I have a problem with the "*" character.

      The error message doesn't appear on the "blur" event with letters in the input field.

      It works fine on the submit though.

       

      Here is my xhtml :

       

      <h:body>

           <h:form>

                <rich:panel header="Person" style="height: 500px;">

                     <h:panelGrid columns="2">

                          <h:outputText value="Name :" />

                          <h:inputText />

                          <h:outputText value="Surname :" />

                          <h:inputText />

                          <h:outputText value="Id :" />

                          <h:inputText validatorMessage="Error on Id">

                               <f:validateRegex pattern="[1-9]*" />

                               <rich:validator event="blur"/>

                          </h:inputText>

                          <h:outputText value="Phone :" />

                          <h:inputText validatorMessage="Error on Phone">

                               <f:validateRegex pattern="[1-9]+" />

                               <rich:validator event="blur"/>

                          </h:inputText>

                          <h:outputText value="Email :" />

                          <h:inputText />

                          <h:commandButton value="test"/>

                     </h:panelGrid>

                </rich:panel>

                <rich:messages/>

           </h:form>

      </h:body>

       

      I'm pretty confident that I could get some other regex to do whatever i'd like todo, but I'd like to know :

      Am I missing something here? Is my regex ok (allowing only numbers)?

      Or is it some king of a bug (the error message appear correctly on the button submit, but not on the blur event).

      I'm new to Richfaces so I wouldn't know.

       

      Here is my setup :

      JDK7

      Tomcat7

      JSF 2.1.3 (mojarra)

      Richfaces 4.1.0 Final

       

       

      On another note, is there a way to format code snippets on the forums?

        • 1. Re: Regex/star caracter not working with rich:validator
          Jorge Campos Newbie

          Hello, Jonathan

           

          I'm not able to test this in a JSF 2 + richfaces 4.x enviroment but I have some tips to you try regarding regex

           

          try change your regular expression to

          <f:validateRegex pattern="([1-9]*)"> <!-- put parentesis envolving the expression -->

           

          the other option is

          <f:validateRegex pattern="([\\d]*)"> <!-- if the regex use posix pattern it should work \d is digits only -->

           

          an another one is

          <f:validateRegex pattern="([1-9]{1,})"> <!-- it allow only number between 1 and 9 at least with 1 character -->

           

          Try this options and see what happens

           

          Jorge Campos

           

          EDIT: forgot to mention about the other question

          Yes, there is. Just click in insert button on editor and choose the language that you want to highlight the sintax