1

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

youngster
  • 41
  • 6
  • 2
    Your code does not even show `VALID_NAME_REGEX ` – Scary Wombat Sep 10 '21 at 02:34
  • 1
    Have you imported the Pattern class? `import java.util.regex.Pattern;` Also, best to leave solution due-date out of your question as that has no bearing on the underlying question itself or how this site works. – Hovercraft Full Of Eels Sep 10 '21 at 02:34
  • 2
    The `java.util.regex` might be not supported by cn1. I see `com.codename1.util.regex` in the docs instead. The list of supported classes you can find here https://www.codenameone.com/javadoc/ – fnklstn Sep 10 '21 at 13:26

1 Answers1

3

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.

Shai Almog
  • 51,749
  • 5
  • 35
  • 65