Easy Form Validation (no JavaScript)

Поділитися
Вставка
  • Опубліковано 3 жов 2024
  • For basic front-end form validation, reach for html! (Of course, you'll want to validate on the server, too, but it couldn't be easier to provide a good experience on the front-end.
    CodePen link: codepen.io/Cod...
    ---------------------------------------
    🌐 Connect With Me 🌐
    Website: codinginpublic...
    Blog: chrispenningto...
    Twitter: / cpenned
    Patreon: / coding_in_public
    Buy Me a Coffee: www.buymeacoff...
  • Навчання та стиль

КОМЕНТАРІ • 26

  • @ChristinaCodes
    @ChristinaCodes 10 місяців тому +4

    Nice! I didn’t know about the title thing-your videos are always full of cool tricks 😊

    • @DontFollowZim
      @DontFollowZim 10 місяців тому

      Same. Title was new to me. Too bad you didn't go into the css pseudo-classes to style (in)valid fields.

    • @CodinginPublic
      @CodinginPublic  10 місяців тому

      Yeah, pseudo classes are awesome. It’s hard in that it’ll start validating on input which isn’t my favorite experience. I prefer to add that styling on blur() with js for that reason.

    • @CodinginPublic
      @CodinginPublic  10 місяців тому +1

      Glad you enjoyed it! Now gotta muse about other tricks to keep up the trend! lol

  • @raldskie23
    @raldskie23 10 місяців тому

    I always do this to clients, but my manager always tell me to have a custom validator - but it can consume time (which i dont like). And the funny thing for me is that i didnt received any negative feedback to the default validator from the end users.
    Most beginner devs dont know this. Kudos to you, Chris. 🔥

    • @CodinginPublic
      @CodinginPublic  10 місяців тому

      Yeah, it’s hard. I typically add much more robust validation for full builds. But for simple sites for friends, I love these little helpers.

  • @davidsiewert8649
    @davidsiewert8649 9 місяців тому +1

    Much better way: show a checklist of rules, that change color/icon depending if you input met the criteria or not while typing

    • @CodinginPublic
      @CodinginPublic  9 місяців тому

      Yep, like I said, this is more for quick forms but for prod sites, you'd want a more advanced solutions.

  • @IainSimmons
    @IainSimmons 10 місяців тому

    Great video! Didn't know about the title! I wonder if that's in all browsers...
    Also, just a tip on regex, you can use \D to represent anything that isn't a number digit, and \d for any digit instead of [0-9].
    It's good that you mentioned that you need to be careful with the validation because there's so many edge cases and you don't want users to not be able to complete the form.

  • @chrizzzly_hh
    @chrizzzly_hh 10 місяців тому +1

    This is a nice quicktip, though having the REGEX pattern right is always a pain, since there are so many local differences!
    Also, since you ALWAYS have to check/sanitize the data in the backend (since people can just edit HTML and remove frontend-pattern matching), it usually makes sense to build the form in the backend to have the same regex pattern matching in the frontend AND backend to reduce duplicates and therefore differences in the future.

    • @CodinginPublic
      @CodinginPublic  10 місяців тому +1

      agreed. For a full validation, I’d want the same checks and sanitation on front and backend. I used this pattern matching on a little custom website for a few friends to input data for a Christmas gift exchange. But it’s a cool little tool for something small like that.

  • @K.Huynh.
    @K.Huynh. 10 місяців тому +1

    Thank for sharing! so cool ❤

  • @topalek
    @topalek 10 місяців тому +1

    nice tutorial. thx!

  • @varrelaljabaar
    @varrelaljabaar 10 місяців тому

    Thank you this very helpful

  • @godofwar8262
    @godofwar8262 10 місяців тому +1

    Hi your videos are always great can you make more videos on form handling And validation in react , next js without library and by the way did you watch gta6 trailer

    • @CodinginPublic
      @CodinginPublic  10 місяців тому +1

      I may! No promises, but thanks for the idea!

  • @alexanderkomanov4151
    @alexanderkomanov4151 9 місяців тому

    Amazing!!!!

  • @adnanamin3666
    @adnanamin3666 10 місяців тому

    Super helpful as always. 😃

  • @it-s-me-mohit
    @it-s-me-mohit 10 місяців тому

    Can we get this working while we are writing and not after submitting the form??

    • @CodinginPublic
      @CodinginPublic  10 місяців тому

      Not with this validation. There are lots of thoughts on when and how to show error states in form, but you’d have to use JS to show on input.

    • @IainSimmons
      @IainSimmons 10 місяців тому

      You could add an event listener to an input and report validity:
      // Assuming you have input set from a querySelector or in a loop via querySelectorAll.forEach
      input.addEventListener("input", (event) => {
      if (event.target.value) {
      event.target.reportValidity();
      }
      });