IP address or not?

The name of the pictureThe name of the pictureThe name of the pictureClash Royale CLAN TAG#URR8PPP











up vote
1
down vote

favorite













An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.




Input: An IP address,



Valid format: a.b.c.d where a, b, c or d can be 0 or a number not having 0 at first position.



Output: 0 or 1



Test Cases:




  • 1.160.10.240 - valid


  • 192.001.32.47 - invalid


  • 1.2.3. - invalid


  • 1.2.3 - invalid


  • 0.00.10.255 - invalid


  • 192.168.1.1 - valid


  • 1.2.$.4 - invalid


  • 255.160.0.34 - valid

This is code-golf, so fewest bytes will win!










share|improve this question









New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
    – Jo King
    1 hour ago







  • 1




    Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like Hello World! or 123.-34.0.1*2?
    – Jo King
    1 hour ago











  • I will add some test cases soon!
    – rv7
    1 hour ago










  • You didn't really answer any questions about the format. For example, the python answer fails a case like a.b.c.d
    – Jo King
    1 hour ago










  • Why 1.1.1.999 is lost
    – l4m2
    1 hour ago














up vote
1
down vote

favorite













An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.




Input: An IP address,



Valid format: a.b.c.d where a, b, c or d can be 0 or a number not having 0 at first position.



Output: 0 or 1



Test Cases:




  • 1.160.10.240 - valid


  • 192.001.32.47 - invalid


  • 1.2.3. - invalid


  • 1.2.3 - invalid


  • 0.00.10.255 - invalid


  • 192.168.1.1 - valid


  • 1.2.$.4 - invalid


  • 255.160.0.34 - valid

This is code-golf, so fewest bytes will win!










share|improve this question









New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.















  • 1




    I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
    – Jo King
    1 hour ago







  • 1




    Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like Hello World! or 123.-34.0.1*2?
    – Jo King
    1 hour ago











  • I will add some test cases soon!
    – rv7
    1 hour ago










  • You didn't really answer any questions about the format. For example, the python answer fails a case like a.b.c.d
    – Jo King
    1 hour ago










  • Why 1.1.1.999 is lost
    – l4m2
    1 hour ago












up vote
1
down vote

favorite









up vote
1
down vote

favorite












An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.




Input: An IP address,



Valid format: a.b.c.d where a, b, c or d can be 0 or a number not having 0 at first position.



Output: 0 or 1



Test Cases:




  • 1.160.10.240 - valid


  • 192.001.32.47 - invalid


  • 1.2.3. - invalid


  • 1.2.3 - invalid


  • 0.00.10.255 - invalid


  • 192.168.1.1 - valid


  • 1.2.$.4 - invalid


  • 255.160.0.34 - valid

This is code-golf, so fewest bytes will win!










share|improve this question









New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.












An IP address is a 32-bit numeric address written as four numbers separated by periods. Each number can be zero to 255.




Input: An IP address,



Valid format: a.b.c.d where a, b, c or d can be 0 or a number not having 0 at first position.



Output: 0 or 1



Test Cases:




  • 1.160.10.240 - valid


  • 192.001.32.47 - invalid


  • 1.2.3. - invalid


  • 1.2.3 - invalid


  • 0.00.10.255 - invalid


  • 192.168.1.1 - valid


  • 1.2.$.4 - invalid


  • 255.160.0.34 - valid

This is code-golf, so fewest bytes will win!







code-golf string number decision-problem






share|improve this question









New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.











share|improve this question









New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









share|improve this question




share|improve this question








edited 6 mins ago





















New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.









asked 1 hour ago









rv7

1063




1063




New contributor




rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.





New contributor





rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.






rv7 is a new contributor to this site. Take care in asking for clarification, commenting, and answering.
Check out our Code of Conduct.







  • 1




    I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
    – Jo King
    1 hour ago







  • 1




    Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like Hello World! or 123.-34.0.1*2?
    – Jo King
    1 hour ago











  • I will add some test cases soon!
    – rv7
    1 hour ago










  • You didn't really answer any questions about the format. For example, the python answer fails a case like a.b.c.d
    – Jo King
    1 hour ago










  • Why 1.1.1.999 is lost
    – l4m2
    1 hour ago












  • 1




    I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
    – Jo King
    1 hour ago







  • 1




    Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like Hello World! or 123.-34.0.1*2?
    – Jo King
    1 hour ago











  • I will add some test cases soon!
    – rv7
    1 hour ago










  • You didn't really answer any questions about the format. For example, the python answer fails a case like a.b.c.d
    – Jo King
    1 hour ago










  • Why 1.1.1.999 is lost
    – l4m2
    1 hour ago







1




1




I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago





I'd recommend a truthy/falsey value rather than 1/0. Or even two distinct sets of outputted values
– Jo King
1 hour ago





1




1




Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like Hello World! or 123.-34.0.1*2?
– Jo King
1 hour ago





Also, some more test cases would be nice. Will the input conform to an IP address-like format or can it be stuff like Hello World! or 123.-34.0.1*2?
– Jo King
1 hour ago













I will add some test cases soon!
– rv7
1 hour ago




I will add some test cases soon!
– rv7
1 hour ago












You didn't really answer any questions about the format. For example, the python answer fails a case like a.b.c.d
– Jo King
1 hour ago




You didn't really answer any questions about the format. For example, the python answer fails a case like a.b.c.d
– Jo King
1 hour ago












Why 1.1.1.999 is lost
– l4m2
1 hour ago




Why 1.1.1.999 is lost
– l4m2
1 hour ago










3 Answers
3






active

oldest

votes

















up vote
2
down vote














JavaScript (Node.js), 54 bytes





x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k


Try it online!






share|improve this answer






















  • I have added some test cases!
    – rv7
    1 hour ago










  • @rv7 Still problem?
    – l4m2
    1 hour ago

















up vote
1
down vote














05AB1E, 19 bytes



'.¡©g4Q®0Å?_*®žz‹«P


Try it online or verify all test cases.



Explanation:





'.¡ '# Split the input by "."
© # Save it in the register (without popping)
g4Q # Check if the size is 4
®0Å?_ # Check for each that they do NOT start with a "0"
®žz‹ # Check if each is smaller than 256
* « # Merge all results together
P # Check if all are truthy (and output implicitly)





share|improve this answer



























    up vote
    0
    down vote














    Retina 0.8.2, 24 bytes



    .0
    a
    d+.d+.d+.d+


    Try it online!






    share|improve this answer




















    • 255.160.0.34 is a valid IP address
      – rv7
      6 mins ago










    Your Answer




    StackExchange.ifUsing("editor", function ()
    return StackExchange.using("mathjaxEditing", function ()
    StackExchange.MarkdownEditor.creationCallbacks.add(function (editor, postfix)
    StackExchange.mathjaxEditing.prepareWmdForMathJax(editor, postfix, [["\$", "\$"]]);
    );
    );
    , "mathjax-editing");

    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: "200"
    ;
    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',
    convertImagesToLinks: false,
    noModals: false,
    showLowRepImageUploadWarning: true,
    reputationToPostImages: null,
    bindNavPrevention: true,
    postfix: "",
    onDemand: true,
    discardSelector: ".discard-answer"
    ,immediatelyShowMarkdownHelp:true
    );



    );






    rv7 is a new contributor. Be nice, and check out our Code of Conduct.









     

    draft saved


    draft discarded


















    StackExchange.ready(
    function ()
    StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174455%2fip-address-or-not%23new-answer', 'question_page');

    );

    Post as a guest






























    3 Answers
    3






    active

    oldest

    votes








    3 Answers
    3






    active

    oldest

    votes









    active

    oldest

    votes






    active

    oldest

    votes








    up vote
    2
    down vote














    JavaScript (Node.js), 54 bytes





    x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k


    Try it online!






    share|improve this answer






















    • I have added some test cases!
      – rv7
      1 hour ago










    • @rv7 Still problem?
      – l4m2
      1 hour ago














    up vote
    2
    down vote














    JavaScript (Node.js), 54 bytes





    x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k


    Try it online!






    share|improve this answer






















    • I have added some test cases!
      – rv7
      1 hour ago










    • @rv7 Still problem?
      – l4m2
      1 hour ago












    up vote
    2
    down vote










    up vote
    2
    down vote










    JavaScript (Node.js), 54 bytes





    x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k


    Try it online!






    share|improve this answer















    JavaScript (Node.js), 54 bytes





    x=>x.split`.`.every(t=>!k--<=t&t<256&+t+x==t+x,k=4)*!k


    Try it online!







    share|improve this answer














    share|improve this answer



    share|improve this answer








    edited 1 hour ago

























    answered 1 hour ago









    l4m2

    3,7781430




    3,7781430











    • I have added some test cases!
      – rv7
      1 hour ago










    • @rv7 Still problem?
      – l4m2
      1 hour ago
















    • I have added some test cases!
      – rv7
      1 hour ago










    • @rv7 Still problem?
      – l4m2
      1 hour ago















    I have added some test cases!
    – rv7
    1 hour ago




    I have added some test cases!
    – rv7
    1 hour ago












    @rv7 Still problem?
    – l4m2
    1 hour ago




    @rv7 Still problem?
    – l4m2
    1 hour ago










    up vote
    1
    down vote














    05AB1E, 19 bytes



    '.¡©g4Q®0Å?_*®žz‹«P


    Try it online or verify all test cases.



    Explanation:





    '.¡ '# Split the input by "."
    © # Save it in the register (without popping)
    g4Q # Check if the size is 4
    ®0Å?_ # Check for each that they do NOT start with a "0"
    ®žz‹ # Check if each is smaller than 256
    * « # Merge all results together
    P # Check if all are truthy (and output implicitly)





    share|improve this answer
























      up vote
      1
      down vote














      05AB1E, 19 bytes



      '.¡©g4Q®0Å?_*®žz‹«P


      Try it online or verify all test cases.



      Explanation:





      '.¡ '# Split the input by "."
      © # Save it in the register (without popping)
      g4Q # Check if the size is 4
      ®0Å?_ # Check for each that they do NOT start with a "0"
      ®žz‹ # Check if each is smaller than 256
      * « # Merge all results together
      P # Check if all are truthy (and output implicitly)





      share|improve this answer






















        up vote
        1
        down vote










        up vote
        1
        down vote










        05AB1E, 19 bytes



        '.¡©g4Q®0Å?_*®žz‹«P


        Try it online or verify all test cases.



        Explanation:





        '.¡ '# Split the input by "."
        © # Save it in the register (without popping)
        g4Q # Check if the size is 4
        ®0Å?_ # Check for each that they do NOT start with a "0"
        ®žz‹ # Check if each is smaller than 256
        * « # Merge all results together
        P # Check if all are truthy (and output implicitly)





        share|improve this answer













        05AB1E, 19 bytes



        '.¡©g4Q®0Å?_*®žz‹«P


        Try it online or verify all test cases.



        Explanation:





        '.¡ '# Split the input by "."
        © # Save it in the register (without popping)
        g4Q # Check if the size is 4
        ®0Å?_ # Check for each that they do NOT start with a "0"
        ®žz‹ # Check if each is smaller than 256
        * « # Merge all results together
        P # Check if all are truthy (and output implicitly)






        share|improve this answer












        share|improve this answer



        share|improve this answer










        answered 13 mins ago









        Kevin Cruijssen

        32k554173




        32k554173




















            up vote
            0
            down vote














            Retina 0.8.2, 24 bytes



            .0
            a
            d+.d+.d+.d+


            Try it online!






            share|improve this answer




















            • 255.160.0.34 is a valid IP address
              – rv7
              6 mins ago














            up vote
            0
            down vote














            Retina 0.8.2, 24 bytes



            .0
            a
            d+.d+.d+.d+


            Try it online!






            share|improve this answer




















            • 255.160.0.34 is a valid IP address
              – rv7
              6 mins ago












            up vote
            0
            down vote










            up vote
            0
            down vote










            Retina 0.8.2, 24 bytes



            .0
            a
            d+.d+.d+.d+


            Try it online!






            share|improve this answer













            Retina 0.8.2, 24 bytes



            .0
            a
            d+.d+.d+.d+


            Try it online!







            share|improve this answer












            share|improve this answer



            share|improve this answer










            answered 13 mins ago









            Okx

            12.2k27100




            12.2k27100











            • 255.160.0.34 is a valid IP address
              – rv7
              6 mins ago
















            • 255.160.0.34 is a valid IP address
              – rv7
              6 mins ago















            255.160.0.34 is a valid IP address
            – rv7
            6 mins ago




            255.160.0.34 is a valid IP address
            – rv7
            6 mins ago










            rv7 is a new contributor. Be nice, and check out our Code of Conduct.









             

            draft saved


            draft discarded


















            rv7 is a new contributor. Be nice, and check out our Code of Conduct.












            rv7 is a new contributor. Be nice, and check out our Code of Conduct.











            rv7 is a new contributor. Be nice, and check out our Code of Conduct.













             


            draft saved


            draft discarded














            StackExchange.ready(
            function ()
            StackExchange.openid.initPostLogin('.new-post-login', 'https%3a%2f%2fcodegolf.stackexchange.com%2fquestions%2f174455%2fip-address-or-not%23new-answer', 'question_page');

            );

            Post as a guest













































































            Comments

            Popular posts from this blog

            What does second last employer means? [closed]

            List of Gilmore Girls characters

            One-line joke