-2

I'm having trouble for checking combination for letter and number, for domain validation which is the TLD not include on input form. And for this combination:

  • letters(upper or lowercase)
  • numbers(0-9)
  • underscore (_)
  • dash (-)
  • point (.)
  • no spaces! or other characters

and for examples:

  • "total23" = OK
  • "total-23" = OK
  • "total_23" = OK
  • "total-" = not OK
  • "total_" = not OK
  • "total " = not OK
  • "total@" = not OK

I've read this tutorial, but still haven't found the answer for my case. regular expression for letters, numbers and - _

alexistdev
  • 57
  • 12
  • This is a good resource to fool around with regular expressions and get a hand to it. https://regexr.com/ – Zac Feb 03 '19 at 02:50

1 Answers1

-1

Assume your "TLD" contains "allowed characters", and must start and end with a letter or digit:

^[A-Za-z0-9]+([._-][A-Za-z0-9]+)*$
iBug
  • 35,554
  • 7
  • 89
  • 134