Skip to content
Advertisement

regEx codenameon

i’m working in the last part of my project in java i used pattern regExp for email and password verification and now i tried to use them in codenameone but it didn’t work maybe it’s because of the syntaxe or the import i searched but i found noting

here’s the pattern i declared

public static final Pattern VALID_EMAIL_ADDRESS_REGEX = Pattern.compile("^[A-Z0-9._%+-]+@[A-Z0-9.-]+\.[A-Z]{2,6}$", Pattern.CASE_INSENSITIVE);
public static final Pattern VALID_PASSWORD_REGEX = Pattern.compile("^(?=.*[0-9])(?=.*[a-z])(?=.*[A-Z])(?=.*[!@#&()–[{}]:;',?/*~$^+=<>]).{8,20}$", Pattern.CASE_INSENSITIVE);

and i called it like this

import static edu.esprit.pidev.utils.Statics.VALID_EMAIL_ADDRESS_REGEX;
import static edu.esprit.pidev.utils.Statics.VALID_PASSWORD_REGEX;
import java.util.regex.Matcher;



public class Validator {

public Validator() {
}

public boolean testEmail(String mail) {
    Matcher matcher = VALID_EMAIL_ADDRESS_REGEX.matcher(mail);
    return matcher.find();
}

   public boolean testPassword(String password) {
    Matcher matcher = VALID_PASSWORD_REGEX.matcher(password);
    return matcher.find();
}

but when i run the project here’ sthe problem

error: cannot find symbol
public static final Pattern VALID_NAME_REGEX = Pattern.compile("^[a-zA-Z]{3,30}$", Pattern.CASE_INSENSITIVE);


 symbol:   variable Pattern
  location: class Statics

please i’m really stuck i need to fix this tonight cause i present my project in few hours

Advertisement

Answer

You imported the incorrect package probably due to IDE completion. Notice that this is less likely to happen if you use the newer Maven project structures. See this JavaDoc: https://www.codenameone.com/javadoc/com/codename1/util/regex/package-summary.html

You need to import the classes from com.codename1.util.regex for pattern matching in Codename One.

User contributions licensed under: CC BY-SA
8 People found this is helpful
Advertisement