| Previous | Home | Next |
Tag description: JSF <f:validateRegex>tag registers a LongRangeValidator instance on the UIcomponent associated with the enclosing tag.
LongRangeValidator is a Validator that checks the value of the corresponding component against specified minimum and maximum values.Code
<f:validateRegex>
Example :
Step 1: Welcome page of Example
<%--
Name= welcomeJSF.jsp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%--
This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>r4r.co.in</title>
</head>
<body>
<h1><h:outputText value="Tag <f:validateRegex > Example"/></h1>
<h:form id="validateRegex">
<%-- Display error message --%>
<h:message for="validateRegex:email" style="color:red" />
<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
<h:outputLabel value="Choose Email ID" />
<h:inputText id="email" value="#{validateRegex.email}"
required="true" validatorMessage="Invalid Email ID" >
<%-- Tag <f:validateRegex> use here --%>
<f:validateRegex pattern=
"^([_A-Za-z0-9-.]*@([A-Za-z0-9-])+((\\.com)|(\\.co.in)|(\\.net))$)" />
</h:inputText>
<h:commandButton action="#{validateRegex.submit()}" value="Submit" />
<h:commandButton action="#{validateRegex.reset()}" value="reset" />
</h:panelGrid>
<BR><BR>
<%-- Display result --%>
<h:panelGrid rendered="#{validateRegex.flag != false}">
Email ID: <h:outputText value="#{validateRegex.email}" />
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>
Step 2: ManagedBean class for provide logic in program
<%--
Name= welcomeJSF.jsp
--%>
<%@page contentType="text/html" pageEncoding="UTF-8"%>
<%@taglib prefix="f" uri="http://java.sun.com/jsf/core"%>
<%@taglib prefix="h" uri="http://java.sun.com/jsf/html"%>
<!DOCTYPE HTML PUBLIC "-//W3C//DTD HTML 4.01 Transitional//EN"
"http://www.w3.org/TR/html4/loose.dtd">
<%--
This file is an entry point for JavaServer Faces application.
--%>
<f:view>
<html>
<head>
<meta http-equiv="Content-Type" content="text/html; charset=UTF-8"/>
<title>r4r.co.in</title>
</head>
<body>
<h1><h:outputText value="Tag <f:validateRegex > Example"/></h1>
<h:form id="validateRegex">
<%-- Display error message --%>
<h:message for="validateRegex:email" style="color:red" />
<h:panelGrid columns="2" cellpadding="2" cellspacing="2">
<h:outputLabel value="Choose Email ID" />
<h:inputText id="email" value="#{validateRegex.email}"
required="true" validatorMessage="Invalid Email ID" >
<%-- Tag <f:validateRegex> use here --%>
<f:validateRegex pattern="^([_A-Za-z0-9-.]*@([A-Za-z0-9-])
+((\\.com)|(\\.co.in)|(\\.net))$)" />
</h:inputText>
<h:commandButton action="#{validateRegex.submit()}" value="Submit" />
<h:commandButton action="#{validateRegex.reset()}" value="reset" />
</h:panelGrid>
<BR><BR>
<%-- Display result --%>
<h:panelGrid rendered="#{validateRegex.flag != false}">
Email ID: <h:outputText value="#{validateRegex.email}" />
</h:panelGrid>
</h:form>
</body>
</html>
</f:view>
Output :
| Previous | Home | Next |