HTML5: Problem with operator not in the Pattern attribute of input text

Asked

Viewed 55 times

4

I want to make input text allow only the following strings:

site.com; site.com.br; site123.com123.br; site-123.com.br. But never: site-123-.com.br

My expression was like this:

(([a-z0-9-]{3,})[^-])+\.([a-z0-9]{2,})(([.]{1})([a-z]{2}))?

That way, when I type: site.co*/@m.br, it’s accepting.

That is, I want you to accept strokes, but never at the end of the first string or before the first dot.

1 answer

1


Renan,

I put this expression together:

^[a-z0-9][a-z0-9-]{1,61}[a-z0-9](\.[a-z]{3,}(\.[a-z]{2})?)$

I did some tests, it solves the dash problem and validates several domain names. See if it meets your need.

  • Thank you, Humberto! Solved my question! I just saw how you did in your expression, and I added little else to mine: (([w]{3})\.)?[a-z0-9](([a-z0-9-]{3,}))[a-z0-9]+\.([a-z0-9]{2,})(([.]{1})([a-z]{2}))?

Browser other questions tagged

You are not signed in. Login or sign up in order to post.