在GWT中验证

Ama*_*ngh 4 java gwt

我正在使用GWT并希望使用java代码验证电子邮件,即使用正则表达式,但是当我使用代码时:

/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */

package org.ArosysLogin.client;

import java.util.regex.Matcher;
import java.util.regex.Pattern;

public class EmailValidator{

      private Pattern pattern;
      private Matcher matcher;

      private static final String EMAIL_PATTERN =
                   "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$";

      public EmailValidator(){
          pattern = Pattern.compile(EMAIL_PATTERN);
      }

      /**
       * Validate hex with regular expression
       * @param hex hex for validation
       * @return true valid hex, false invalid hex
       */
      public boolean validate(final String hex){

          matcher = pattern.matcher(hex);
          return matcher.matches();


      }
}
Run Code Online (Sandbox Code Playgroud)

.它在build.xml中给我运行时错误.你能告诉我为什么会发生这种情况以及它的解决方案是什么.

Pet*_*ego 10

Java正则表达式在GWT中不可用.你应该使用GWT的RegExp.


小智 6

这是用于验证电子邮件ID的代码.我检查了一下.它在GWT中运行良好.

String  s ="survi@gmail.com";
Boolean b = s.matches(
 "^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$");
System.out.println("email is " + b);
Run Code Online (Sandbox Code Playgroud)