1 Replies - 494 Views - Last Post: 03 May 2013 - 06:54 PM Rate Topic: -----

#1 javaFresh  Icon User is offline

  • New D.I.C Head

Reputation: 0
  • View blog
  • Posts: 1
  • Joined: 03-May 13

JSF Change Validation Pattern Based on DropDownList value

Posted 03 May 2013 - 06:00 PM

I am adding a credit card validation to a form
<h:selectOneMenu value="#{validationBean.cardType}">
   	<f:selectItem itemValue="Visa" itemLabel="Visa" />
   	<f:selectItem itemValue="Master" itemLabel="Master" />
   	<f:selectItem itemValue="Discover" itemLabel="Discover" />
      
        </h:selectOneMenu>
  <h:inputText id="cardInputText" required="true"
               requiredMessage="Please enter a valid credit card number"
               value="#{validationBean.card}"
               validatorMessage="Invalid credit number format">
               <f:validator validatorId="validation.CreditCardValidator" />
            </h:inputText>



I am just looking for some advice on what is the best approach for changing the validation pattern based on the cardType or drop down list. In my CreditCardValidator I have only Visa set up. I want to use multiple conditional patterns.

 


private static final String VISA_PATTERN = "^4[0-9]{12}(?:[0-9]{3})?$";
private static final String DISCOVER_PATTERN = "^5[1-5][0-9]{14}$";
	
public CreditCardValidator(){
        
          pattern = Pattern.compile(VISA_PATTERN);
          

            
	}


Any help would be greatly appreciated! Thanks!

Is This A Good Question/Topic? 0
  • +

Replies To: JSF Change Validation Pattern Based on DropDownList value

#2 pbl  Icon User is offline

  • There is nothing you can't do with a JTable
  • member icon

Reputation: 8343
  • View blog
  • Posts: 31,890
  • Joined: 06-March 08

Re: JSF Change Validation Pattern Based on DropDownList value

Posted 03 May 2013 - 06:54 PM

this one is for g00se which is on GMT time zone... you should get a correct answer in a few hours
Was This Post Helpful? 0
  • +
  • -

Page 1 of 1