带有一些符号的名称的正则表达式

时间:2022-02-11 21:40:31

I was scratching my head for regular expression to validate name field which will accept
Only characters Space Dash apostrophe and dot

我正在摸索正规表达式验证名称字段,它将接受只有字符Space Dash撇号和点

I tried

/^[0-9A-Za-z_@'-]+$/

but this is going wrong

但这是错误的

4 个解决方案

#1


0  

Try this expresion

试试这个表达

/^[0-9A-Za-z .@'-]+$/

#2


0  

Try this expression

试试这个表达

^[a-zA-Z\s-'.]+$

#3


0  

I think this below code allows what you expecting.

我认为以下代码可以满足您的期望。

([A-Z .'-])\w+

Output Sample:

Edit the Expression
gskinner.com
OMG-B

Let try above code and let us know.

让我们尝试上面的代码,让我们知道。

#4


0  

You will have to escape the '-' char because it has another meaning in regexes. The following should take care of what you need

你将不得不逃避' - 'char,因为它在regex中有另一种含义。以下内容应该照顾您的需要

^[A-z.'\-@_ ]+$

#1


0  

Try this expresion

试试这个表达

/^[0-9A-Za-z .@'-]+$/

#2


0  

Try this expression

试试这个表达

^[a-zA-Z\s-'.]+$

#3


0  

I think this below code allows what you expecting.

我认为以下代码可以满足您的期望。

([A-Z .'-])\w+

Output Sample:

Edit the Expression
gskinner.com
OMG-B

Let try above code and let us know.

让我们尝试上面的代码,让我们知道。

#4


0  

You will have to escape the '-' char because it has another meaning in regexes. The following should take care of what you need

你将不得不逃避' - 'char,因为它在regex中有另一种含义。以下内容应该照顾您的需要

^[A-z.'\-@_ ]+$