简体   繁体   English

至少 1 个大写字母,后跟数字、可选的破折号和空格

[英]At least 1 capital, followed by numeric, optional dashes and space

I want to implement regex which allows only capital, numeric, optional dash and space.我想实现只允许大写、数字、可选破折号和空格的正则表达式。

Format is: At least 1 capital, followed by numeric and optional dash and space.格式为:至少 1 个大写,后跟数字和可选的破折号和空格。

I tried我试过

/^[A-Z0-9- ]+$/

But it's not working.但它不起作用。 Can anyone please help.任何人都可以请帮忙。 Thanks in advance.提前致谢。

You have mentioned "Atleast 1 capital followed by numeric and optional dash and space"您已经提到“至少 1 个大写字母后跟数字和可选的破折号和空格”

this is the regular expression for at least one Capital letter at first followed by any number of letters, hypens and spaces这是至少一个大写字母的正则表达式,后面跟着任意数量的字母、连字符和空格

^[A-Z][a-zA-Z0-9 -]*$

In case you meant Capital letter at any position,如果您的意思是任何位置的大写字母,

this is the regular expression for at least one Capital letter at any position , and only containing zero or more letters[upper and lowercase] , numbers, space and hyphen at other positions这是任意位置至少一个大写字母的正则表达式,其他位置仅包含零个或多个字母[大写和小写]、数字、空格和连字符

^[a-zA-Z0-9 -]*[A-Z][a-zA-Z0-9 -]*$

This is valid这是有效的

This is valid 2这是有效的 2

This is n*t valid这是 n*t 有效

thiS is valid 3这是有效的 3

this Is -4 valid这是 -4 有效

This + is not VALID.此 + 无效。

--- this is Valid 2 -- --- 这是有效的 2 --

声明:本站的技术帖子网页,遵循CC BY-SA 4.0协议,如果您需要转载,请注明本站网址或者原文地址。任何问题请咨询:yoyou2525@163.com.

 
粤ICP备18138465号  © 2020-2024 STACKOOM.COM