[英]E-mail Validation Using Regex not working for jsf?
我在我的jsp頁面使用JSF 2.1。 我在點擊忘記密碼DIV時出現的DIV標記中包含了一個h:inputText和一個h:commandButton 。 我想驗證客戶端本身的有效電子郵件地址的輸入字段,所以我使用了f:validateRegex和“validatorMessage”,但當我給出錯誤的電子郵件地址說“123gmail.com”時,它似乎仍無法正常工作提交,不輸入任何文字。 它只是重新加載頁面。 誰能幫我...
這是我編輯的JSP頁面代碼供參考
<!DOCTYPE html>
<%@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"%>
<%@page import="com.fla.mbeans.ForgotPass"%>
<html>
<head>
</head>
<body>
<div style="left: 44%;top: 6%;width: 250px; position: relative;padding:20px;cursor: pointer" onclick="copytext()">
<span id="fstyle"><ul>Forgot Password?</ul></span>
</div>
<div id="fgpass" >
<div id="newpass">
<div style="position: absolute;top: 10%;left: 10%;">
<center><h2>PASSWORD RECOVERY</h2></center>
<h4> Enter Your Registered</h4>
<h4>E-Mail Address :</h4>
<f:view>
<h:form>
<center>
<h:inputText id="cmailid" required="true" value="#{forgotPass.mailid}" validatorMessage="Invalid email">
<f:validateRegex pattern="[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]"/>
</h:inputText>
<h:commandButton value="Submit" action="#{forgotPass.fpass}">
</h:commandButton>
</center>
</div>
</div>
</h:form>
</div>
</body>
</f:view>
</html>
我的Css
#fgpass {
position: absolute;
left: 65%;
top: 4%;
border-color: #009900;
border-width: 3px;
border-radius: inherit;
z-index: 800;
}
#newpass{
position: absolute;
z-index: 1000;
height:160px;
width: 250px;
color: midnightblue;
visibility: hidden;
background-color: lavender;
-moz-border-radius: 8px;
border-radius: 8px;
border-width: 3px;
border-color:#444;
}
我的js
function copytext()
{
var unhide=document.getElementById('newpass');
src=document.getElementById('mailid');
unhide.style.visibility='visible';
dest=document.getElementById('cmailid');
dest.value = src.value;
}
任何人都可以告訴我為什么它不起作用或任何其他方式我可以在客戶端進行驗證.....我是新手,請幫助(謝謝)
使用jsf中的f validateRegex進行電子郵件驗證。
使用模式^[_A-Za-z0-9-\\+]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$
用於電子郵件驗證。
例:
<%@ taglib uri="http://java.sun.com/jsf/core" prefix="f"%>
<%@ taglib uri="http://java.sun.com/jsf/html" prefix="h"%>
<f:view>
<style type="text/css">
.error {
color: red;
}
.info {
color: green;
}
</style>
<h:form id="regexForm">
<div>
<h:messages id="messagesId" errorClass="error" infoClass="info"></h:messages>
<h:inputText id="primaryEmailId" validatorMessage="Invalid PrimaryEmail [ Ex: udaykiran.pulipati@gmail.com ]" required="true"
requiredMessage="Please Enter PrimaryEmail">
<f:validateRegex pattern="^[_A-Za-z0-9-\+]+(\.[_A-Za-z0-9-]+)*@[A-Za-z0-9-]+(\.[A-Za-z0-9]+)*(\.[A-Za-z]{2,})$"></f:validateRegex>
</h:inputText>
</div>
<div>
<h:commandButton value="Submit"></h:commandButton>
</div>
</h:form>
</f:view>
聲明:本站的技術帖子網頁,遵循CC BY-SA 4.0協議,如果您需要轉載,請注明本站網址或者原文地址。任何問題請咨詢:yoyou2525@163.com.