Regular Expression for Organisation name
How to write a regular expression for validating a organisation name which allows Alphanumeric as the starting characters and onl开发者_运维技巧y 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 Welcome @ 123Invalid Names
&Hercules
Colgate!() .Youtube @InculeIs 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 comments 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
- Welcome @ 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
精彩评论