Logo Questions Linux Laravel Mysql Ubuntu Git Menu
 

JavaScript RegEx double name

I want to only allow one capital letter at start, and one more if(after hyphen) and that your able to write only one hyphen, so that u can write a double name, like Klas-Bertil and nothing else.

Shall allow:

Klas
Klas-Bertil
Fredrick-Patrick

not:

KlAs-
KLaS-bErtIl
Fre-Dr-IckP-aTrick

Dont know if im making myself understood? :)

Thanks in advance!

like image 273
likfarmenhet Avatar asked Jul 03 '26 12:07

likfarmenhet


1 Answers

try this:

^[A-Z]?[a-z]*(?:-[A-Z][a-z]*)?$

if you'd like to force capital letter at the start:

^[A-Z][a-z]*(?:-[A-Z][a-z]*)?$
like image 127
davidrac Avatar answered Jul 05 '26 03:07

davidrac



Donate For Us

If you love us? You can donate to us via Paypal or buy me a coffee so we can maintain and grow! Thank you!