Board Logo

numberic ranges?
mickknutson - 8/30/2006 at 11:43 AM

I want to validate an input from 2 to 10 only.
Thus, a value of 1 or 11 is NOT valid.

How can I do this please....


tigra - 8/30/2006 at 01:39 PM

you can write the custom validation function or use this (not so elegant) regexp

/^0*[2-9]|(10)$/


mickknutson - 8/30/2006 at 04:20 PM

Well, I am new to your format, so would it look something like:

'deferredPeriod' : {
'l': 'Deferred Period', // label
'r': true, // required
'f': 'unsigned', // format (see below)
't': 't_deferredPeriod', // id of the element to highlight if input not validated

'm': /^0*[2-9]|(10)$/, // must match specified form field
'mn': 2, // minimum length
'mx': 10 // maximum length
}


mickknutson - 8/30/2006 at 04:23 PM

OR, do I have to get the PRO version to attain this?

Also, can the validation in the PRO check whether date1 is before date2?


tigra - 8/31/2006 at 09:34 AM

in configuration:

'f': /^0*[2-9]|(10)$/,

or you can add a_formats list in validator.js

'myFormat': /^w+$/,

and then call it by name in configuration:

'f': 'myFormat',


mickknutson - 8/31/2006 at 10:27 AM

in jsVal, they have the concept of min and max value, not just min and max length.

How hard would it be to add those 2 types?


tigra - 8/31/2006 at 12:37 PM

not very hard. look at other complex types defined in validator.js for sample.


mickknutson - 9/6/2006 at 01:19 PM

Quote:
Originally posted by tigra
you can write the custom validation function or use this (not so elegant) regexp

/^0*[2-9]|(10)$/


what would 0 to 115 be?

'f': /^0*[0-9]|(115)$/,


mickknutson - 9/6/2006 at 02:35 PM

This does not work:


var a_fields = {
'deferredPeriod' : {
'l': 'Deferred Period', // label
'r': true, // required
'f': /^0*[2-9]|(10)$/, // format (see below)
't': 't_deferredPeriod' // id of the element to highlight if input not validated
}

},


The validation is not called at all


tigra - 9/6/2006 at 02:40 PM

it will be something like:
/^0*d{1,2}|(10[0-9])|(11[0-5])$/
but it's not the right road to go, it can become really ugly if you need changes, larger numbers or fractions, just write something like
if (typeof(myNumber) == 'Number' && !(myNumber%1) && myNumber >= 0 && myNumber <= 115)
deal


dtakis - 11/30/2006 at 04:58 AM

Quote:
Originally posted by tigra
it will be something like:
/^0*d{1,2}|(10[0-9])|(11[0-5])$/
but it's not the right road to go, it can become really ugly if you need changes, larger numbers or fractions, just write something like
if (typeof(myNumber) == 'Number' && !(myNumber%1) && myNumber >= 0 && myNumber <= 115)
deal


Sorry, but i didn't understand your suggestion! Where should we put this expression?


tigra - 11/30/2006 at 08:48 AM

read 5th posting in this thread


Demetrius - 6/8/2007 at 06:41 AM

You can add field attributes. For example 'hi' and 'lo':
var a_fields = {
...
'some_input' : {'l':'SomeInput','r':true,'f':'unsigned','t':'t_some_input','hi': 2,'lo':10},
...
}

and in validator.js:
// check format
...
//check the digit
else if (this.a_fields[n_key]['lo'] && parseInt(this.a_fields[n_key]['v']) > this.a_fields[n_key]['lo']){
this.a_fields[n_key].n_error = 4;
n_errors_count++;
}

else if (this.a_fields[n_key]['hi'] && parseInt(this.a_fields[n_key]['v']) < this.a_fields[n_key]['hi']){
this.a_fields[n_key].n_error = 4;
n_errors_count++;
}
// check match


Softcomplex: http://www.softcomplex.com/
Back to forum: http://www.softcomplex.com/forum/