Validating a Social Security Number

How to get this to work in your own page

Insert the following snippets to get the JSF SSNValidator to work in your JSP page. Note since this is a validator it uses the validator tag to set itself up. Note more information about the validator can be found in the API documentation.

This demo does not require you to enter an SSN, if you do not enter an SSN it will return to the same page without giving an error. However if you do enter some values for the SSN it will call the validator to validate the SSN. The input field here requires you to enter the SSN without any dashes, because we are not using the SSNConverter companion class.

    <%@taglib prefix="ssn" uri="http://www.manorrock.com/tld/jsf/ssn"%>

    <h:inputText value="#{ssnBean.ssn}">
        <f:validator validatorId="com.manorrock.jsf.ssn.validator.SSNValidator"/>
    </h:inputText>

    

Actual demo

Enter a SSN: