admin管理员组文章数量:1277393
How to write a regular expression for validating a organisation name which allows Alphanumeric as the starting characters and only special characters like .
, -
, #
and &
.
I tried but it's not working
/^[a-z]|\d?[a-zA-Z0-9]?[a-zA-Z0-9\s&@.]+$
Some Valid Names
Hercules.Cycle
Herbal & Product
Wele @ 123
Invalid Names
&Hercules
Colgate!()
.Youtube
@Incule
How to write a regular expression for validating a organisation name which allows Alphanumeric as the starting characters and only special characters like .
, -
, #
and &
.
I tried but it's not working
/^[a-z]|\d?[a-zA-Z0-9]?[a-zA-Z0-9\s&@.]+$
Some Valid Names
Hercules.Cycle
Herbal & Product
Wele @ 123
Invalid Names
&Hercules
Colgate!()
.Youtube
@Incule
- 1 Please add some samples for which is failing. – Shamim Hafiz - MSFT Commented Jun 28, 2011 at 10:24
- 2 And how did you try it? What is not working? Please add valid and invalid inputs. – Felix Kling Commented Jun 28, 2011 at 10:25
- 4 Please provide some examples of valid and invalid names – Rob Cowie Commented Jun 28, 2011 at 10:25
- 4 Why does an organization name need validating in the first place? What about umlauts and other special characters that might be present in a pany name? – Pekka Commented Jun 28, 2011 at 10:26
- 3 I have seen organization names with parentheses, Japanese characters, exclamation marks and even question marks. – user142019 Commented Jun 28, 2011 at 11:20
5 Answers
Reset to default 6Is that what you want?
^[A-Z]([a-zA-Z0-9]|[- @\.#&!])*$
You guys can use this below validation ,
As per our requirement from client, "Company Name" can have only 'single space' in between words along with few permitted special characters in it.
/^[a-zA-Z0-9-@.{}#&!()]+(\s[a-zA-Z0-9-@{}.#&!()]+)+(\s[a-zA-Z-@.#&!()]+)?$/
Output:- Correct/Positive Response. These below mentioned outputs are allowed..
- @arshaa Technologies (m91) HYD
- @9Arshaa Technologies (HYD) IND
- #AT&T {IND} HYD
- #Apple.India {HYD} (INDIA)
Negative/Incorrect response. These below mentioned few outputs will not be allowed, according to above mentioned RegEx. As they contain multiple spaces or Special Characters not in RegEx.
- @arshaa _Technologies (m91) HYD
- @9Arshaa --Technologies (HYD) IND
- #AT&T {IND} HYD.
- #Apple. -^India {HYD} $(INDIA)
Note: Please feel free to update your answers in ments section for further modification of this RegEx.
I've made and tested the above regular expression and it solves all what you mentioned:
/^[.@&]?[a-zA-Z0-9 ]+[ !.@&()]?[ a-zA-Z0-9!()]+/
Below all checks off.
Some Valid Names
- Hercules.Cycle
- Herbal & Product
- Wele @ 123
Invalid Names
- &Hercules
- Colgate!()
- .Youtube
- @Incule
Try this pattern:
^\w[\w.\-#&\s]*$
or
^[a-zA-Z0-9][a-zA-Z0-9\.\-#&\s]*$
^[A-Z]([a-zA-Z0-9.-_,]|[- @.#&!])*$
This would allow certain special characters after the first word
Sample Names:
1. Hoyt, Gilman & Esp
2. Y 105 Kgfy
本文标签: javascriptRegular Expression for Organisation nameStack Overflow
版权声明:本文标题:javascript - Regular Expression for Organisation name - Stack Overflow 内容由网友自发贡献,该文观点仅代表作者本人, 转载请联系作者并注明出处:http://www.betaflare.com/web/1741265077a2368305.html, 本站仅提供信息存储空间服务,不拥有所有权,不承担相关法律责任。如发现本站有涉嫌抄袭侵权/违法违规的内容,一经查实,本站将立刻删除。
发表评论