Validation in GWT

I use GWT and I want to check email this way with java code, i.e. with regular expressions, but when I use the code:

/*
 * 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();


      }
}

. This gives me a runtime error in the build.xml file. Please tell me why this is happening and what is its solution.

+3
source share
4 answers

Java regex is not available in GWT. You must use GWT RegExp .

+10
source

This is the code to verify the email id. I checked it out. It works great in 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);
+5
source

- :

if(email.matches("^[_A-Za-z0-9-]+(\\.[_A-Za-z0-9-]+)*@[A-Za-z0-9]+(\\.[A-Za-z0-9]+)*(\\.[A-Za-z]{2,})$")){
    GWT.log("Email Address Valid");
}else{
 GWT.log("Email Address Invalid");
 valid = false;
}
+1

, . , java.lang.String.

, :

public boolean validate(final String hex){
  return ((hex==null) || hex.matches(EMAIL_PATTERN));
}
0

All Articles