mickknutson
Junior Member
Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
|
| posted on 8/30/2006 at 11:43 AM |
|
|
numberic ranges?
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
Administrator
Posts: 1982
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 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
Junior Member
Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
|
| posted on 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
Junior Member
Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
|
| posted on 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
Administrator
Posts: 1982
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 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
Junior Member
Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
|
| posted on 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
Administrator
Posts: 1982
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 8/31/2006 at 12:37 PM |
|
|
not very hard. look at other complex types defined in validator.js for sample.
|
|
|
mickknutson
Junior Member
Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
|
| posted on 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
Junior Member
Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
|
| posted on 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
Administrator
Posts: 1982
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 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
Newbie
Posts: 1
Registered: 11/30/2006
Location: Athens
Member Is Offline
|
| posted on 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
Administrator
Posts: 1982
Registered: 6/17/2002
Location: US, CO
Member Is Offline
|
| posted on 11/30/2006 at 08:48 AM |
|
|
read 5th posting in this thread
|
|
|
Demetrius
Newbie
Posts: 1
Registered: 6/8/2007
Member Is Offline
|
| posted on 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
|
|
|