Regex pattern for first name without whitespace or numbersA comprehensive regex for phone number validationJavaScript Regex pattern - baffledJS regex name patternHow to allow whitespace in RegexHow to check a string in Java equals to a regex pattern?Regex for Mobile Number ValidationRegEx to find pattern “ JUNKCHARS” in Javascript stringJava regex: match expression delimited by whitespacesRegex to find evaluate number patternRegex detect any repeated character but with optional whitespace between
Beyond Futuristic Technology for an Alien Warship?
Calculate the Ultraradical
What organs or modifications would be needed to have hairy fish?
Windows 10 deletes lots of tiny files super slowly. Anything that can be done to speed it up?
Approximate CO2 emissions for shipping a parcel from one location to another
How to add the real hostname in the beginning of Linux cli command
Can you cure a Gorgon's Petrifying Breath before it finishes turning a target to stone?
Do my potential customers need to understand the "meaning" of a logo, or just recognize it?
Diminished data rate with logic output optoisolator
Why does `FindFit` fail so badly in this simple case?
How do my husband and I get over our fear of having another difficult baby?
Did Tolkien ever write about a Heaven or Hell for Men?
Booting Ubuntu from USB drive on MSI motherboard -- EVERYTHING fails
Worlds with different mathematics and logic
Why is the population of post-Soviet states declining?
How can I visualize an ordinal variable predicting a continuous outcome?
Implementation of a Thread Pool in C++
Can an energy drink or chocolate before an exam be useful ? What sort of other edible goods be helpful?
Creating specific options in `Manipulate[]`
How to bring home documents from work?
Replacing cord for IBM model M keyboard
How do I introduce dark themes?
How to level a picture frame hung on a single nail?
Isn't the detector always measuring, and thus always collapsing the state?
Regex pattern for first name without whitespace or numbers
A comprehensive regex for phone number validationJavaScript Regex pattern - baffledJS regex name patternHow to allow whitespace in RegexHow to check a string in Java equals to a regex pattern?Regex for Mobile Number ValidationRegEx to find pattern “ JUNKCHARS” in Javascript stringJava regex: match expression delimited by whitespacesRegex to find evaluate number patternRegex detect any repeated character but with optional whitespace between
.everyoneloves__top-leaderboard:empty,.everyoneloves__mid-leaderboard:empty,.everyoneloves__bot-mid-leaderboard:empty margin-bottom:0;
I have this regex pattern
/^[^-s][^0-9][a-zA-Zs-]+$/
I am a bit confused on why when I test it on https://www.regextester.com/
My pattern allows one single number to be added before the string. Meaning that if I type in '2Mantas' it will still accept it whereas '22Mantas' will fail the test. I do not want any numbers or whitespace to be allowed. Any ideas anyone?
regex
add a comment
|
I have this regex pattern
/^[^-s][^0-9][a-zA-Zs-]+$/
I am a bit confused on why when I test it on https://www.regextester.com/
My pattern allows one single number to be added before the string. Meaning that if I type in '2Mantas' it will still accept it whereas '22Mantas' will fail the test. I do not want any numbers or whitespace to be allowed. Any ideas anyone?
regex
1
Please provide some sample inputs that should pass, and some that should fail.
– esqew
Mar 28 at 20:09
any string passes if you include one number before it '5steve' '2daniel' etc. but '22steve' would fail.
– Mantas Stanionis
Mar 28 at 20:11
1
Yes, you've indicated that above. Can you provide some inputs that should and should not pass? For example, we can assume that5steve
and2daniel
should not pass, but can you give us an example for what should pass?
– esqew
Mar 28 at 20:12
add a comment
|
I have this regex pattern
/^[^-s][^0-9][a-zA-Zs-]+$/
I am a bit confused on why when I test it on https://www.regextester.com/
My pattern allows one single number to be added before the string. Meaning that if I type in '2Mantas' it will still accept it whereas '22Mantas' will fail the test. I do not want any numbers or whitespace to be allowed. Any ideas anyone?
regex
I have this regex pattern
/^[^-s][^0-9][a-zA-Zs-]+$/
I am a bit confused on why when I test it on https://www.regextester.com/
My pattern allows one single number to be added before the string. Meaning that if I type in '2Mantas' it will still accept it whereas '22Mantas' will fail the test. I do not want any numbers or whitespace to be allowed. Any ideas anyone?
regex
regex
asked Mar 28 at 20:07
Mantas StanionisMantas Stanionis
305 bronze badges
305 bronze badges
1
Please provide some sample inputs that should pass, and some that should fail.
– esqew
Mar 28 at 20:09
any string passes if you include one number before it '5steve' '2daniel' etc. but '22steve' would fail.
– Mantas Stanionis
Mar 28 at 20:11
1
Yes, you've indicated that above. Can you provide some inputs that should and should not pass? For example, we can assume that5steve
and2daniel
should not pass, but can you give us an example for what should pass?
– esqew
Mar 28 at 20:12
add a comment
|
1
Please provide some sample inputs that should pass, and some that should fail.
– esqew
Mar 28 at 20:09
any string passes if you include one number before it '5steve' '2daniel' etc. but '22steve' would fail.
– Mantas Stanionis
Mar 28 at 20:11
1
Yes, you've indicated that above. Can you provide some inputs that should and should not pass? For example, we can assume that5steve
and2daniel
should not pass, but can you give us an example for what should pass?
– esqew
Mar 28 at 20:12
1
1
Please provide some sample inputs that should pass, and some that should fail.
– esqew
Mar 28 at 20:09
Please provide some sample inputs that should pass, and some that should fail.
– esqew
Mar 28 at 20:09
any string passes if you include one number before it '5steve' '2daniel' etc. but '22steve' would fail.
– Mantas Stanionis
Mar 28 at 20:11
any string passes if you include one number before it '5steve' '2daniel' etc. but '22steve' would fail.
– Mantas Stanionis
Mar 28 at 20:11
1
1
Yes, you've indicated that above. Can you provide some inputs that should and should not pass? For example, we can assume that
5steve
and 2daniel
should not pass, but can you give us an example for what should pass?– esqew
Mar 28 at 20:12
Yes, you've indicated that above. Can you provide some inputs that should and should not pass? For example, we can assume that
5steve
and 2daniel
should not pass, but can you give us an example for what should pass?– esqew
Mar 28 at 20:12
add a comment
|
3 Answers
3
active
oldest
votes
You have two negation groups so it is saying the first character cannot be whitespace and the second character cannot be a number. If you put the whitespace and digit in the first brackets it will work as desired.
^[^-sd][a-zA-Zs-]+$
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
add a comment
|
The first two rules in your current regular expression break down to the following:
^[^s-]
- the first character in the string should not be a whitespace or a hyphen. This explains why2steve
is accepted -2
is not a whitespace or a hyphen character.[^0-9]
- the second character in the strnig should not be a digit. This iexplains why22steve
is not accepted - the2
in the second position is a digit, which violates this rule.
Assuming you don't want anything but capital and lowercase letters in your first name input, and the name shouldn't start with a whitespace or hyphen character, you can simplify to a subset of your current regular expression:
/^[A-Za-z][A-Za-z-s]+$/
Regex101
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
add a comment
|
This should work
Get string, that starts with exactly one digit, and after this digits should be expression, that contains only strings (greedy)
^d1([a-zA-Z]+)
https://regex101.com/r/wtBwd7/1
add a comment
|
Your Answer
StackExchange.ifUsing("editor", function ()
StackExchange.using("externalEditor", function ()
StackExchange.using("snippets", function ()
StackExchange.snippets.init();
);
);
, "code-snippets");
StackExchange.ready(function()
var channelOptions =
tags: "".split(" "),
id: "1"
;
initTagRenderer("".split(" "), "".split(" "), channelOptions);
StackExchange.using("externalEditor", function()
// Have to fire editor after snippets, if snippets enabled
if (StackExchange.settings.snippets.snippetsEnabled)
StackExchange.using("snippets", function()
createEditor();
);
else
createEditor();
);
function createEditor()
StackExchange.prepareEditor(
heartbeatType: 'answer',
autoActivateHeartbeat: false,
convertImagesToLinks: true,
noModals: true,
showLowRepImageUploadWarning: true,
reputationToPostImages: 10,
bindNavPrevention: true,
postfix: "",
imageUploader:
brandingHtml: "Powered by u003ca class="icon-imgur-white" href="https://imgur.com/"u003eu003c/au003e",
contentPolicyHtml: "User contributions licensed under u003ca href="https://creativecommons.org/licenses/by-sa/4.0/"u003ecc by-sa 4.0 with attribution requiredu003c/au003e u003ca href="https://stackoverflow.com/legal/content-policy"u003e(content policy)u003c/au003e",
allowUrls: true
,
onDemand: true,
discardSelector: ".discard-answer"
,immediatelyShowMarkdownHelp:true
);
);
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406040%2fregex-pattern-for-first-name-without-whitespace-or-numbers%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
3 Answers
3
active
oldest
votes
3 Answers
3
active
oldest
votes
active
oldest
votes
active
oldest
votes
You have two negation groups so it is saying the first character cannot be whitespace and the second character cannot be a number. If you put the whitespace and digit in the first brackets it will work as desired.
^[^-sd][a-zA-Zs-]+$
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
add a comment
|
You have two negation groups so it is saying the first character cannot be whitespace and the second character cannot be a number. If you put the whitespace and digit in the first brackets it will work as desired.
^[^-sd][a-zA-Zs-]+$
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
add a comment
|
You have two negation groups so it is saying the first character cannot be whitespace and the second character cannot be a number. If you put the whitespace and digit in the first brackets it will work as desired.
^[^-sd][a-zA-Zs-]+$
You have two negation groups so it is saying the first character cannot be whitespace and the second character cannot be a number. If you put the whitespace and digit in the first brackets it will work as desired.
^[^-sd][a-zA-Zs-]+$
answered Mar 28 at 20:12
bwingbwing
4746 silver badges9 bronze badges
4746 silver badges9 bronze badges
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
add a comment
|
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
amazing. thank you for the explanation too!
– Mantas Stanionis
Mar 28 at 20:13
add a comment
|
The first two rules in your current regular expression break down to the following:
^[^s-]
- the first character in the string should not be a whitespace or a hyphen. This explains why2steve
is accepted -2
is not a whitespace or a hyphen character.[^0-9]
- the second character in the strnig should not be a digit. This iexplains why22steve
is not accepted - the2
in the second position is a digit, which violates this rule.
Assuming you don't want anything but capital and lowercase letters in your first name input, and the name shouldn't start with a whitespace or hyphen character, you can simplify to a subset of your current regular expression:
/^[A-Za-z][A-Za-z-s]+$/
Regex101
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
add a comment
|
The first two rules in your current regular expression break down to the following:
^[^s-]
- the first character in the string should not be a whitespace or a hyphen. This explains why2steve
is accepted -2
is not a whitespace or a hyphen character.[^0-9]
- the second character in the strnig should not be a digit. This iexplains why22steve
is not accepted - the2
in the second position is a digit, which violates this rule.
Assuming you don't want anything but capital and lowercase letters in your first name input, and the name shouldn't start with a whitespace or hyphen character, you can simplify to a subset of your current regular expression:
/^[A-Za-z][A-Za-z-s]+$/
Regex101
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
add a comment
|
The first two rules in your current regular expression break down to the following:
^[^s-]
- the first character in the string should not be a whitespace or a hyphen. This explains why2steve
is accepted -2
is not a whitespace or a hyphen character.[^0-9]
- the second character in the strnig should not be a digit. This iexplains why22steve
is not accepted - the2
in the second position is a digit, which violates this rule.
Assuming you don't want anything but capital and lowercase letters in your first name input, and the name shouldn't start with a whitespace or hyphen character, you can simplify to a subset of your current regular expression:
/^[A-Za-z][A-Za-z-s]+$/
Regex101
The first two rules in your current regular expression break down to the following:
^[^s-]
- the first character in the string should not be a whitespace or a hyphen. This explains why2steve
is accepted -2
is not a whitespace or a hyphen character.[^0-9]
- the second character in the strnig should not be a digit. This iexplains why22steve
is not accepted - the2
in the second position is a digit, which violates this rule.
Assuming you don't want anything but capital and lowercase letters in your first name input, and the name shouldn't start with a whitespace or hyphen character, you can simplify to a subset of your current regular expression:
/^[A-Za-z][A-Za-z-s]+$/
Regex101
edited Mar 28 at 20:13
answered Mar 28 at 20:11
esqewesqew
24k21 gold badges79 silver badges110 bronze badges
24k21 gold badges79 silver badges110 bronze badges
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
add a comment
|
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
if you add a single digit before the name it still passes on regextester.com
– Mantas Stanionis
Mar 28 at 20:12
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
@MantasStanionis - yes, you're correct, my mistake, I've updated my regex.
– esqew
Mar 28 at 20:14
add a comment
|
This should work
Get string, that starts with exactly one digit, and after this digits should be expression, that contains only strings (greedy)
^d1([a-zA-Z]+)
https://regex101.com/r/wtBwd7/1
add a comment
|
This should work
Get string, that starts with exactly one digit, and after this digits should be expression, that contains only strings (greedy)
^d1([a-zA-Z]+)
https://regex101.com/r/wtBwd7/1
add a comment
|
This should work
Get string, that starts with exactly one digit, and after this digits should be expression, that contains only strings (greedy)
^d1([a-zA-Z]+)
https://regex101.com/r/wtBwd7/1
This should work
Get string, that starts with exactly one digit, and after this digits should be expression, that contains only strings (greedy)
^d1([a-zA-Z]+)
https://regex101.com/r/wtBwd7/1
answered Mar 28 at 20:18
Kamil NajaKamil Naja
2,4993 gold badges14 silver badges27 bronze badges
2,4993 gold badges14 silver badges27 bronze badges
add a comment
|
add a comment
|
Thanks for contributing an answer to Stack Overflow!
- Please be sure to answer the question. Provide details and share your research!
But avoid …
- Asking for help, clarification, or responding to other answers.
- Making statements based on opinion; back them up with references or personal experience.
To learn more, see our tips on writing great answers.
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
StackExchange.ready(
function ()
StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fstackoverflow.com%2fquestions%2f55406040%2fregex-pattern-for-first-name-without-whitespace-or-numbers%23new-answer', 'question_page');
);
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Sign up or log in
StackExchange.ready(function ()
StackExchange.helpers.onClickDraftSave('#login-link');
);
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Sign up using Google
Sign up using Facebook
Sign up using Email and Password
Post as a guest
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
Required, but never shown
1
Please provide some sample inputs that should pass, and some that should fail.
– esqew
Mar 28 at 20:09
any string passes if you include one number before it '5steve' '2daniel' etc. but '22steve' would fail.
– Mantas Stanionis
Mar 28 at 20:11
1
Yes, you've indicated that above. Can you provide some inputs that should and should not pass? For example, we can assume that
5steve
and2daniel
should not pass, but can you give us an example for what should pass?– esqew
Mar 28 at 20:12