RegEx for valid email structure validating false positives with pattern()

I am using the following RegEx with pattern() to validate an input

pattern('^[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$')

This should validate inputs like "example.yes" or even "a.b" and invalidate inputs like "pie". However, this seems to validate any character input that is longer than 2 characters without a "." in it.

Is this a bug? How can I get around this issue?

Why do you use custom validation with regexp if Wappler has build-in email format validation?

What is the built-in email format validation you are referring to?
Is it different from type="email" attr for HTML input tag?

Main reason is that I want to validate a basic domain input (not just email) and I also have other validations that I am checking on top of that, which I want to display in a consistent way that I can style myself.

I'm referring to Text Input -> Validation Rules -> Text - Email

I tried this - thanks for the suggestion, but I want to:

  1. Validate a basic domain input (not email)
  2. Want to display different validation error messages checked by other regex patterns that look consistent
  3. I want to validate inputs before submission (not on submit)

I understand this complicates things but just wondering if there is something inherently wrong or defective with my regex I showed above if that is how I want to do the validation (or if i want to expand this first regex for a more custom validation)?

I don't see anything wrong with your validation, it works fine in my tests, when i use the pattern validation rule:

data-rule-pattern="^[a-zA-Z0-9-]+\.[a-zA-Z0-9-.]+$"

Screenshot 2024-12-17 at 12.01.08

Screenshot 2024-12-17 at 12.01.17

1 Like

Add event on un-focus - validate.

1 Like

Thank you

Thanks for the suggestion

1 Like