Giter Site home page Giter Site logo

iamaliybi / lv-validation Goto Github PK

View Code? Open in Web Editor NEW
3.0 3.0 0.0 136 KB

lv-validation is a Javascript library that provides a comprehensive set of validation rules for incoming form data. Our library includes convenient and customizable validation rules, such as checking for required fields, validating email addresses, and ensuring values are unique in a given database table.

License: MIT License

TypeScript 99.02% JavaScript 0.98%
form-validation laravel-validation lv-validation validation

lv-validation's Introduction

Ali Yaghoubi

About Me:

I am a Javascript Developer! I am currently studying for a bachelor's degree in computer engineering. My favorite programming language is Javascript, I have experience in PHP and Laravel too.

Languages and Tools:



lv-validation's People

Contributors

iamaliybi avatar

Stargazers

 avatar  avatar  avatar

Watchers

 avatar  avatar

lv-validation's Issues

Need some clarification about this library

I would like to thank you for this library.
I am refactoring my javascript code to remove any script that uses jQuery.

I am currently replacing the jquery-validation:1.19.5 library, while doing research I found this one, and I would like to know if it will suit me in my use cases.

Below is a general use case

Register Form

Capture d’écran 2023-10-01 à 18 41 25

const phoneNumberSelector = document.querySelector("#phone_number")
const countryIso = document.querySelector("#country_iso")
const intlInput = (await import("Utils/IntelInput")).intl(phoneNumberSelector)

// Add custom method to validate phone number
$.validator.addMethod("validPhoneNumber", value => {
  if (value !== "") {
    const formattedNumber = intlInput.getNumber(), isValid = intlInput.isValidNumber()
    phoneNumberSelector.value = formattedNumber

    if (isValid && value.length > 8) {
      phoneNumberSelector.value = formattedNumber
      countryIso.value = intlInput.getSelectedCountryData().iso2
    }

    return isValid
  }

  return true
}, "Please enter a valid phone number.")


$("#form").validate({
  lang: "ar", // Define errors language
  rules: {
      gender: { // Radio button
        required: true,
      },
      firstname: {
        required: true,
      },
      lastname: {
        required: true,
      },
      email: {
        required: true,
        email: true,
      },
      phone_number: { // Input field
        required: true,
        validPhoneNumber: true, // Custom validation method
      },
      password: {
        required: true,
        minlength: 8,
      },
      password_confirm: {
        required: true,
        minlength: 8,
        equalTo: '#password',
      },
    },
})

$("#form").on("submit", function (e) {
  resetFormErrors($(this))

  if (!$(this).valid()) {
    e.preventDefault()
  }
})

The $.validator.addMethod() signature is:

  • name the name of the method used in the rules.
  • callback function to validate the field, it's return true if no error, false otherwise.
  • message used to display message error if callback returns false.

In the $.validate() params we can specify the language used.

Finally, my question is.
Can this library satisfy this use case ?

thanks in advance.

Recommend Projects

  • React photo React

    A declarative, efficient, and flexible JavaScript library for building user interfaces.

  • Vue.js photo Vue.js

    🖖 Vue.js is a progressive, incrementally-adoptable JavaScript framework for building UI on the web.

  • Typescript photo Typescript

    TypeScript is a superset of JavaScript that compiles to clean JavaScript output.

  • TensorFlow photo TensorFlow

    An Open Source Machine Learning Framework for Everyone

  • Django photo Django

    The Web framework for perfectionists with deadlines.

  • D3 photo D3

    Bring data to life with SVG, Canvas and HTML. 📊📈🎉

Recommend Topics

  • javascript

    JavaScript (JS) is a lightweight interpreted programming language with first-class functions.

  • web

    Some thing interesting about web. New door for the world.

  • server

    A server is a program made to process requests and deliver data to clients.

  • Machine learning

    Machine learning is a way of modeling and interpreting data that allows a piece of software to respond intelligently.

  • Game

    Some thing interesting about game, make everyone happy.

Recommend Org

  • Facebook photo Facebook

    We are working to build community through open source technology. NB: members must have two-factor auth.

  • Microsoft photo Microsoft

    Open source projects and samples from Microsoft.

  • Google photo Google

    Google ❤️ Open Source for everyone.

  • D3 photo D3

    Data-Driven Documents codes.