[lnkForumImage]
TotalShareware - Download Free Software

Confronta i prezzi di migliaia di prodotti.
Asp Forum
 Home | Login | Register | Search 


 

Forums >

comp.lang.javascript

JavaScript validation with JOVIAL.js extended

Simon Blackwell

3/1/2016 5:39:00 PM

JOVIAL the light weight JavaScript object validation library has been enhanced to support validation of email, ISBN, credit card (CC), and IP address (IP). Extending the type checking requires just one line of code per type. In addition, default values and write once support have been added.

https://github.com/anywhich...

4 Answers

Michael Haufe (\"TNO\")

3/2/2016 1:37:00 AM

0

On Tuesday, March 1, 2016 at 11:39:24 AM UTC-6, Simon Blackwell wrote:
> JOVIAL the light weight JavaScript object validation library has been enhanced to support validation of email, ISBN, credit card (CC), and IP address (IP). Extending the type checking requires just one line of code per type.. In addition, default values and write once support have been added.
>
> https://github.com/anywhich...


A five second glance raises the following issue:

#1 you are using a regex to validate credit card numbers:

/^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/

This is a valid CC number: 6372178847694560
This is NOT a valid CC number: 6372178847694506

Compare your approach to the use of the Luhn Formula.

Simon Blackwell

3/2/2016 2:30:00 PM

0

On Tuesday, March 1, 2016 at 8:37:41 PM UTC-5, Michael Haufe (TNO) wrote:
> On Tuesday, March 1, 2016 at 11:39:24 AM UTC-6, Simon Blackwell wrote:
> > JOVIAL the light weight JavaScript object validation library has been enhanced to support validation of email, ISBN, credit card (CC), and IP address (IP). Extending the type checking requires just one line of code per type. In addition, default values and write once support have been added.
> >
> > https://github.com/anywhich...
>
>
> A five second glance raises the following issue:
>
> #1 you are using a regex to validate credit card numbers:
>
> /^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/
>
> This is a valid CC number: 6372178847694560
> This is NOT a valid CC number: 6372178847694506
>
> Compare your approach to the use of the Luhn Formula.

Thanks for your input. JOVIAL will be updated to use the Luhn Formula in a release scheduled for next week. This extension will be done in a manner such that functions rather than RegExp can be an alternate general means of extending types.

John Harris

3/2/2016 3:23:00 PM

0

On Tue, 1 Mar 2016 17:37:27 -0800 (PST), "Michael Haufe (TNO)"
<tno@thenewobjective.com> wrote:


<snip>
>This is a valid CC number: 6372178847694560
<snip>

That is, of course, after spaces have been removed.

John

Simon Blackwell

3/3/2016 12:34:00 PM

0

On Tuesday, March 1, 2016 at 8:37:41 PM UTC-5, Michael Haufe (TNO) wrote:
> On Tuesday, March 1, 2016 at 11:39:24 AM UTC-6, Simon Blackwell wrote:
> > JOVIAL the light weight JavaScript object validation library has been enhanced to support validation of email, ISBN, credit card (CC), and IP address (IP). Extending the type checking requires just one line of code per type. In addition, default values and write once support have been added.
> >
> > https://github.com/anywhich...
>
>
> A five second glance raises the following issue:
>
> #1 you are using a regex to validate credit card numbers:
>
> /^3(?:[47]\d([ -]?)\d{4}(?:\1\d{4}){2}|0[0-5]\d{11}|[68]\d{12})$|^4(?:\d\d\d)?([ -]?)\d{4}(?:\2\d{4}){2}$|^6011([ -]?)\d{4}(?:\3\d{4}){2}$|^5[1-5]\d\d([ -]?)\d{4}(?:\4\d{4}){2}$|^2014\d{11}$|^2149\d{11}$|^2131\d{11}$|^1800\d{11}$|^3\d{15}$/
>
> This is a valid CC number: 6372178847694560
> This is NOT a valid CC number: 6372178847694506
>
> Compare your approach to the use of the Luhn Formula.

A new version has been posted that incorporates the Luhn Formula.