String Validations

Asked

Viewed 57 times

2

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

If anyone can clarify how this works I appreciate.

  • 1

    Hello all jewels, huh? if they are regular expressions and in programming help a lot even if you have books written only for this type of content, I believe it means exception the bar then can put any character followed by arroba and soon after follow any cacatere and then if you have a list with two characters and finally finish, if I forgot or missed something I apologize I did it quickly. the following is a link to basic concepts of regular expressions: http://www.devmedia.com.br/conceitos-basicos-sobre-expressoes-regulares-em-java/27539

1 answer

5


The explanation of this regex is thus:

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

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

There is a very good site to analyze regex, take a look here: https://regex101.com/r/tP8yC9/1

  • And are these regular expressions a standard for all languages? It’s the same thing in java and jquery or javascript?

  • @Vynstus for the most part. I think your example works well in other languages. In the link I passed in the answer you can change language in the left bar. You can also have a look here: https://en.wikipedia.org/wiki/Comparison_of_regular_expression_engines

  • @Vynstus the answer was what you were looking for?

  • Yes, sorry for the delay. Thank you.

Browser other questions tagged

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