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;








-2















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?










share|improve this question



















  • 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 and 2daniel should not pass, but can you give us an example for what should pass?

    – esqew
    Mar 28 at 20:12

















-2















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?










share|improve this question



















  • 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 and 2daniel should not pass, but can you give us an example for what should pass?

    – esqew
    Mar 28 at 20:12













-2












-2








-2








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?










share|improve this question














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






share|improve this question













share|improve this question











share|improve this question




share|improve this question










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 that 5steve and 2daniel should not pass, but can you give us an example for what should pass?

    – esqew
    Mar 28 at 20:12












  • 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 and 2daniel 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












3 Answers
3






active

oldest

votes


















0
















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-]+$





share|improve this answer

























  • amazing. thank you for the explanation too!

    – Mantas Stanionis
    Mar 28 at 20:13


















0
















The first two rules in your current regular expression break down to the following:




  1. ^[^s-] - the first character in the string should not be a whitespace or a hyphen. This explains why 2steve is accepted - 2 is not a whitespace or a hyphen character.


  2. [^0-9] - the second character in the strnig should not be a digit. This iexplains why 22steve is not accepted - the 2 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






share|improve this answer



























  • 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


















0
















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






share|improve this answer



























    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
    );



    );














    draft saved

    draft discarded
















    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









    0
















    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-]+$





    share|improve this answer

























    • amazing. thank you for the explanation too!

      – Mantas Stanionis
      Mar 28 at 20:13















    0
















    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-]+$





    share|improve this answer

























    • amazing. thank you for the explanation too!

      – Mantas Stanionis
      Mar 28 at 20:13













    0














    0










    0









    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-]+$





    share|improve this answer













    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-]+$






    share|improve this answer












    share|improve this answer



    share|improve this answer










    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

















    • 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













    0
















    The first two rules in your current regular expression break down to the following:




    1. ^[^s-] - the first character in the string should not be a whitespace or a hyphen. This explains why 2steve is accepted - 2 is not a whitespace or a hyphen character.


    2. [^0-9] - the second character in the strnig should not be a digit. This iexplains why 22steve is not accepted - the 2 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






    share|improve this answer



























    • 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















    0
















    The first two rules in your current regular expression break down to the following:




    1. ^[^s-] - the first character in the string should not be a whitespace or a hyphen. This explains why 2steve is accepted - 2 is not a whitespace or a hyphen character.


    2. [^0-9] - the second character in the strnig should not be a digit. This iexplains why 22steve is not accepted - the 2 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






    share|improve this answer



























    • 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













    0














    0










    0









    The first two rules in your current regular expression break down to the following:




    1. ^[^s-] - the first character in the string should not be a whitespace or a hyphen. This explains why 2steve is accepted - 2 is not a whitespace or a hyphen character.


    2. [^0-9] - the second character in the strnig should not be a digit. This iexplains why 22steve is not accepted - the 2 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






    share|improve this answer















    The first two rules in your current regular expression break down to the following:




    1. ^[^s-] - the first character in the string should not be a whitespace or a hyphen. This explains why 2steve is accepted - 2 is not a whitespace or a hyphen character.


    2. [^0-9] - the second character in the strnig should not be a digit. This iexplains why 22steve is not accepted - the 2 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







    share|improve this answer














    share|improve this answer



    share|improve this answer








    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

















    • 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











    0
















    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






    share|improve this answer





























      0
















      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






      share|improve this answer



























        0














        0










        0









        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






        share|improve this answer













        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







        share|improve this answer












        share|improve this answer



        share|improve this answer










        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































            draft saved

            draft discarded















































            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.




            draft saved


            draft discarded














            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





















































            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







            Popular posts from this blog

            Kamusi Yaliyomo Aina za kamusi | Muundo wa kamusi | Faida za kamusi | Dhima ya picha katika kamusi | Marejeo | Tazama pia | Viungo vya nje | UrambazajiKuhusu kamusiGo-SwahiliWiki-KamusiKamusi ya Kiswahili na Kiingerezakuihariri na kuongeza habari

            Swift 4 - func physicsWorld not invoked on collision? The Next CEO of Stack OverflowHow to call Objective-C code from Swift#ifdef replacement in the Swift language@selector() in Swift?#pragma mark in Swift?Swift for loop: for index, element in array?dispatch_after - GCD in Swift?Swift Beta performance: sorting arraysSplit a String into an array in Swift?The use of Swift 3 @objc inference in Swift 4 mode is deprecated?How to optimize UITableViewCell, because my UITableView lags

            Access current req object everywhere in Node.js ExpressWhy are global variables considered bad practice? (node.js)Using req & res across functionsHow do I get the path to the current script with Node.js?What is Node.js' Connect, Express and “middleware”?Node.js w/ express error handling in callbackHow to access the GET parameters after “?” in Express?Modify Node.js req object parametersAccess “app” variable inside of ExpressJS/ConnectJS middleware?Node.js Express app - request objectAngular Http Module considered middleware?Session variables in ExpressJSAdd properties to the req object in expressjs with Typescript