Skip to content
New issue

Have a question about this project? Sign up for a free GitHub account to open an issue and contact its maintainers and the community.

By clicking “Sign up for GitHub”, you agree to our terms of service and privacy statement. We’ll occasionally send you account related emails.

Already on GitHub? Sign in to your account

Rule Wishlist #9

Closed
7 of 12 tasks
PascaleBeier opened this issue Jul 19, 2017 · 20 comments
Closed
7 of 12 tasks

Rule Wishlist #9

PascaleBeier opened this issue Jul 19, 2017 · 20 comments

Comments

@PascaleBeier
Copy link
Collaborator

PascaleBeier commented Jul 19, 2017

  • before(date, dateFormat)
  • after (date, dateFormat)
  • date(format)
  • regexp(regexp)
  • phone (format)
  • file(extension)
  • divisible (Rule Wishlist #9 (comment))
  • url
    URL Validation
  • matches
    Two fields that should match, e.q. for password confirmations. The v1 API makes that super fuzzy.
  • endswith(string)
    Ensure a given string ends with a given string
  • startswith(string)
    Same as above but starting with
  • contains(string)
@PascaleBeier
Copy link
Collaborator Author

url added in 95237a0

@PascaleBeier
Copy link
Collaborator Author

contains added in 3913b9a

@PascaleBeier
Copy link
Collaborator Author

startsWith added in fff8678

@PascaleBeier
Copy link
Collaborator Author

endsWith added in aa51798

@PascaleBeier
Copy link
Collaborator Author

matches added in 208a5cf

@PegWeb
Copy link

PegWeb commented Mar 9, 2018

Password strength? Say being able to specify for example must contain letter number uppercase lower case symbol and so on.

@PascaleBeier
Copy link
Collaborator Author

PascaleBeier commented Mar 10, 2018 via email

@PascaleBeier
Copy link
Collaborator Author

PascaleBeier commented Mar 10, 2018 via email

@niladam
Copy link

niladam commented Mar 27, 2018

It would be nice to have a startsWithOr(1,2) which will allow you to specify that it needs to start with either 1 or 2..

@PascaleBeier
Copy link
Collaborator Author

@Niladem cool idea!

I could do that for any rule with n additional arguments. Definitely doing that.

@StefCoene
Copy link

I need a 'divisible by' rule.
Example: Input need to be divisible my 0.5: so 1.5 is valid, 1.6 is not.

I think this code should do the trick:
divisible: (input, divisible) => {
return isInteger(Number(input.value/divisible));
},

@StefCoene
Copy link

And I also need an other rule. I need to match a field so the date is in the format YYYY-MM-DD.
Matching the general format is enough. So MM > 13 is allowed.
Maybe it can be a general regexp so it's usable in other situations?

Stef

@PascaleBeier
Copy link
Collaborator Author

Hey Stef,

Worthy suggestions! Feel free to send a PR. I'm short on freetime atm.

@StefCoene
Copy link

I'm working on a new bootstrap 4 project and we need to do some input validation. Your code seems the only form validation code that works with bootstrap 4.
But we are missing some rules. It's not really urgent because the project is still in development state. So take your time.

Stef

@PascaleBeier
Copy link
Collaborator Author

@StefCoene Check out v2.1.0

@niladam
Copy link

niladam commented May 4, 2018

Hey @PascaleBeier how about this ? (please keep in mind that my programming skills aren't how i'd like them to be)

  startsWithOr: (input, string, string2) => {
    /**
     * @since 2.1.1
     * @param string string: String the input value should start with
     * @param string2 string: Second string the input value should start with
     * @example 1,2
     * @error Your input should contain either 1 or 2.
     * @description Require the input value to start with a given string
     * or a different string.
     */
    // Check first string
    let istrue = false;
    if ( startsWith(input.value, string) ) {
        istrue = true
    }
    if ( startsWith(input.value, string2) ) {
        istrue = true
    }
    return istrue;
},

@niladam
Copy link

niladam commented May 4, 2018

I think it would be safe to verify if there are 2 strings in the function, and if not, basically just run startsWith on it. If there are 2 strings, than they'd both need to be verified..

@PascaleBeier
Copy link
Collaborator Author

PascaleBeier commented May 4, 2018

Hey @niladam,

The reason I didnt implement it yet is that I want to find a solution to dynamically add these ...Or-Rules. Will look at that again these days.

Your Code is nice! You could also use the or Operator :)

@StefCoene
Copy link

Cool, thanks for the quick response!

For the divisible, I also need to check if something is divisible by 0.2.
For instance, 3.1 % 0.2: false, 4.2 % 0.2: true
I think this should do the trick:

if ( number < 1 ) {
  return Number(input.value / number) % 1 === 0;
} else { 
  return Number(input.value) % number === 0;
}

@PascaleBeier
Copy link
Collaborator Author

PascaleBeier commented May 4, 2018

@StefCoene TIL that % is no modulo operator but a remainder operator per definition in JavaScript 🛩

Should have tested that more thorough!

Fixed in d58f8e0 - Which did not ultimately fix it:

I ended up using arbitrary-precision decimal arithmetic via https://github.com/MikeMcl/big.js. Might come in handy in the future. Shipped it with 2.1.2. I cleaned our comments, don't feel offended!

https://jsfiddle.net/57pyawLn/4/

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
Labels
None yet
Projects
None yet
Development

No branches or pull requests

4 participants