开发者

REGEX - validing letter with number OR only letter

Some days, I try to create a specific regex to validate a simple "Name" field开发者_JAVA技巧. Yet even today, could not the way I wanted ...

I would like to validate a field as follows:

  • to write any character A-Z and/or a-z
  • to write numbers since she has some character from A-Z and/or a-z.
  • do not allow write only numbers

For example, valid:

  • Only letters: Microsoft Corporation, Asus Technologies, etc...
  • Letters and Numbers: Tom 182, James 007 Bond, etc... (numbers can be any character position: XXXXX 98998 XXXX 87 XXX )

For example, invalid:

  • 098230983 (only number is invalid!)

The failure code REGEX: (^[a-zA-Z\ \']+$)|([0-9]*[a-z\ \']+$)

PS: regex online: http://gskinner.com/RegExr/

Thanks to all.


You can try with:

^([0-9]*[a-zA-Z][a-zA-Z0-9]*)$

It allows string to start with digits, then it has to contain a letter and after that letter - letters and digits are possible.

Also a question here: what about whitespace characters ? Because in Microsoft Corporation there is one.

If it should be possible to match them too try with:

^([0-9 ]*[a-zA-Z][a-zA-Z0-9 ]*)$
0

上一篇:

下一篇:

精彩评论

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

最新问答

问答排行榜