JSF: Email Address Not Stripping Spaces on Validation

In the following script,    <f:validateRegex pattern="^[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" /> consider trailing spaces as invalid,


I have a task to make it valid, that is even there is trailing spaces, the input filed will pass the regex validation.


So I add this attribute:  οnchange="this.value=this.value.trim()" .The onchange fires before the validations do, so it will act as if the user did not enter any spaces at the beginning or end of the input.


The reason that I didn't modify the regex pattern because I don't want backend work. Because the input value is bound with backend bean, bean or controller need to handle stripping if regex were changed.

 <!-- EMAIL AND EMAIL CONFIRM -->
                    <h:panelGroup id="emailPanel" layout="block" styleClass="myatc-formrow-group">
                        <atcui:formError id="emailMessage" for="enterEmail" ajaxRendered="false" />
                        <atcui:formRow>
                            <h:inputText id="enterEmail"
                                         required="true"
                                         value="#{loginSelectionBean.email}"
                                         οnchange="this.value=this.value.trim()"
                                         maxlength="45"
                                         pt:placeholder="email"
                                         pt:autocapitalize="none"
                                         requiredMessage="Please enter a valid email address."
                                         validatorMessage="Please enter a valid email address. Example: yourname@domain.com">
                                <f:validateRegex pattern="^[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                            </h:inputText>
                        </atcui:formRow>
                        <atcui:formError id="confirmEmailMessage" for="confirmEmail" ajaxRendered="false" />
                        <atcui:formRow>
                            <h:inputText id="confirmEmail"
                                         required="true"
                                         value="#{loginSelectionBean.confirmEmail}"
                                         οnchange="this.value=this.value.trim()"
                                         οnchange="this.value=this.value.trim()"
                                         maxlength="45"
                                         pt:placeholder="reenter email"
                                         pt:autocapitalize="none"
                                         requiredMessage="Email confirmation is required."
                                         validatorMessage="Please enter a valid confirmation email address.">
                                <f:validateRegex pattern="^[\w\.-]*[a-zA-Z0-9_]@[\w\.-]*[a-zA-Z0-9]\.[a-zA-Z][a-zA-Z\.]*[a-zA-Z]" />
                            </h:inputText>
                        </atcui:formRow>
                    </h:panelGroup>

                    <!-- PASSWORD AND PASSWORD CONFIRM -->
                   
                    </h:panelGroup>


  • 0
    点赞
  • 0
    收藏
    觉得还不错? 一键收藏
  • 0
    评论

“相关推荐”对你有帮助么?

  • 非常没帮助
  • 没帮助
  • 一般
  • 有帮助
  • 非常有帮助
提交
评论
添加红包

请填写红包祝福语或标题

红包个数最小为10个

红包金额最低5元

当前余额3.43前往充值 >
需支付:10.00
成就一亿技术人!
领取后你会自动成为博主和红包主的粉丝 规则
hope_wisdom
发出的红包
实付
使用余额支付
点击重新获取
扫码支付
钱包余额 0

抵扣说明:

1.余额是钱包充值的虚拟货币,按照1:1的比例进行支付金额的抵扣。
2.余额无法直接购买下载,可以购买VIP、付费专栏及课程。

余额充值