javascript - validation rule conditional upon value of myVariable -


usung jquery validator, apply rule (regex) if variable (myvariable) has given value.

i thought about...

rules: {     nhi:{regex:function() {             var myvariable =6;             return myvariable =6;}         }, }, 

i thought if expression myvariable=6 evaluates true validation rule applied. , if expression false won't applied. noticed approach seems work, other times doesn't if expression being evaluated. changing code use === instead of = seems force fresh evaluation of expression. not.

ultimately want run validation user ip addresses firstly want understand simple way turn validation on or off javascript.

the following works:

var myvariable =6; ... rules: { nhi:{regex:myvariable ===6}     }, 

so perhaps simple that?

closer goal:

var countrycode ="nz"; ... rules: { nhi:{regex:countrycode ="nz"}     }, 

this turns validation on (if nz) , off otherwise. great. insert geoplugin head:

 <script type="text/javascript" src="http://www.geoplugin.net/javascript.gp"  ></script> 

and change code

var countrycode=geoplugin_countrycode(); ... rules: { nhi:{regex:countrycode ="nz"}     }, 

however seems evaluate false though country nz


Comments

Popular posts from this blog

apache - PHP Soap issue while content length is larger -

asynchronous - Python asyncio task got bad yield -

javascript - Complete OpenIDConnect auth when requesting via Ajax -