String Validations

2

I've been researching how to validate e-mail, dates, hours, etc. And in the case of email, I found a code like this: /^.+@.+\..{2,}$/; . He is incomplete. But I wanted to understand what these symbols are, and what do they represent to validate a string?

If someone can clarify how this works I thank you.

    
asked by anonymous 28.05.2016 / 04:39

1 answer

5

The explanation of this regex is like this:

  

/^.+@.+\..{2,}$/

  • / - opening symbol of the regex object.
  • ^ - indicates start of string
  • .+ - any character less line change, one or more occurrences
  • @ - an "at" character
  • \. - the character point, escaped because in regex the point has a function, so with \ means the character itself and not the function that it usually has in regex
  • .{2,} - any character less line change, two followed or longer
  • $ - end of string
  • / - closing the regex object

There is a very good site for parsing regex, check it out here: link

    
28.05.2016 / 09:19