Support Forum Softcomplex logo
About Us  | Services  | Download  | Order  | Support  | |
| Search | Today's Posts | Stats | Board Rules | Not logged in [ Login | Register ]
go to bottom
Last active: Never

Printable Version | Subscribe | Add to Favourites   Post new thread
Author: Subject: numberic ranges?
mickknutson
Junior Member

Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
posted on 8/30/2006 at 11:43 AM Reply With Quote
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....
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 8/30/2006 at 01:39 PM Reply With Quote

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

/^0*[2-9]|(10)$/
View User's Profile View All Posts By User U2U Member
mickknutson
Junior Member

Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
posted on 8/30/2006 at 04:20 PM Reply With Quote

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
}
View User's Profile View All Posts By User U2U Member
mickknutson
Junior Member

Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
posted on 8/30/2006 at 04:23 PM Reply With Quote

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?
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 8/31/2006 at 09:34 AM Reply With Quote

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',
View User's Profile View All Posts By User U2U Member
mickknutson
Junior Member

Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
posted on 8/31/2006 at 10:27 AM Reply With Quote

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?
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 8/31/2006 at 12:37 PM Reply With Quote

not very hard. look at other complex types defined in validator.js for sample.
View User's Profile View All Posts By User U2U Member
mickknutson
Junior Member

Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
posted on 9/6/2006 at 01:19 PM Reply With Quote

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)$/,
View User's Profile View All Posts By User U2U Member
mickknutson
Junior Member

Posts: 6
Registered: 8/30/2006
Location: San Francisco
Member Is Offline
posted on 9/6/2006 at 02:35 PM Reply With Quote

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
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 9/6/2006 at 02:40 PM Reply With Quote

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
View User's Profile View All Posts By User U2U Member
dtakis
Newbie

Posts: 1
Registered: 11/30/2006
Location: Athens
Member Is Offline
posted on 11/30/2006 at 04:58 AM Reply With Quote

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?
View User's Profile View All Posts By User U2U Member
tigra
Administrator

Posts: 2049
Registered: 6/17/2002
Location: US, CO
Member Is Offline
posted on 11/30/2006 at 08:48 AM Reply With Quote

read 5th posting in this thread
View User's Profile View All Posts By User U2U Member
Demetrius
Newbie

Posts: 1
Registered: 6/8/2007
Member Is Offline
posted on 6/8/2007 at 06:41 AM Reply With Quote

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
View User's Profile View All Posts By User U2U Member
Post new thread

Related Links:
Product Page Product Page
Product Demonstrations Product Demos
Registration Form Validation
Login Form Validation
Free Download Free Download
Product Documentation Documentation
Documenation Page
Change Log
Validators Comparison Table
Support Forum Support Forum
 

Go To Top


Powered by XMB 1.9.1 Nexus
Developed By Aventure Media & The XMB Group © 2002-2004