开发者

What regular expression can validate this type of string?

How do I validate this using a regex in js?

first.last.wrt

OR

开发者_Python百科
first.last

Both are part of email addresses, only the name part in the format mentioned above should validated.

Ex: These should validate using the regex:

john.doe.wrt
john.doe


/^[a-z]+\.[a-z]+(\.wrt)?$/

Based on your example, this would work.


If you only want letters/numbers/underscores to validate:

(\w+?)\.(\w+?)(?:\.wrt)?

If you want anything to validate in the "first" and "last" parts:

(.+?)\.(.+?)(?:\.wrt)?

Capture Groups:

  1. First Name
  2. Last Name


if(/^[a-z]+\.[a-z]+(\.wrt)?$/i.test('the string')) {
    // It validates!
} else {
    // It doesn't...
}

I take it apostrophes and such aren't allowed, but you can add them within the square brackets.

0

上一篇:

下一篇:

精彩评论

暂无评论...
验证码 换一张
取 消

最新问答

问答排行榜