Forum Moderators: open

Message Too Old, No Replies

Spry Modification

Spry Modification

         

typomaniac

5:11 pm on Oct 29, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



This involves Adobe.spry javascript but not being used with Dreamweaver.
First...javascript is not my cup but anyway this one looked simple enough so gave it a shot.
Wanting to validate certain fields for alpha characters only but Spry did not include that--they have just about anything else a person might need though
Looking at the .js file the first validation scenario is for integers which is:

'integer': {
characterMasking: /[\-\+\d]/,
regExpFilter: /^[\-\+]?\d*$/,
validation: function(value, options) {
if (value == '' || value == '-' || value == '+') {
return false;
}
var regExp = /^[\-\+]?\d*$/;
if (!regExp.test(value)) {
return false;
}
options = options || {allowNegative:false};
var ret = parseInt(value, 10);
if (!isNaN(ret)) {
var allowNegative = true;
if (typeof options.allowNegative != 'undefined' && options.allowNegative == false) {
allowNegative = false;
}
if (!allowNegative && value < 0) {
ret = false;
}
} else {
ret = false;
}
return ret;
}
},


Looked like a simple enough solution to modify the regex to /^[a-zA-Z]$/i but I guess that wasn't happening because as it caused the browser to do ignore my efforts.
Is there any way I could change this? I was going to just add another routine to the .js file and name it alpha or something.
The validation is only a server side complimentary thing and is backed with Perl but it does provide a nice convenience on the user end.

Fotiman

7:11 pm on Oct 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



A quick Google found this in the Adobe forums [forums.adobe.com]:

var custom = new Spry.Widget.ValidationTextField("id", "custom", {
validation: function( value, options ){
return /[a-z]/gi.test( value ); // your validation
}
});

typomaniac

10:36 pm on Oct 29, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thanx a million Fotiman--worked like a charm. I had passed right by that one because in the post at Adobe forums the question said it was looking for only allow
    alphanumeric
where I was looking for alpha only. That will teach me to search more venues next time. A good thing also though because anyone else in the same predicament can benefit from your post.
Does need modified a tad though because it will allow anything to be entered as is if an alpha char is included. Testing now with /^[a-z]$/

Fotiman

11:29 pm on Oct 29, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member Top Contributors Of The Month



Ah, good catch. Nice modification. :)

typomaniac

3:57 am on Oct 30, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



I'm back at being confused again--while adding the ^ at the beginning and $ at the end made it impossible to add anything but alpha characters it shows an error if more than one char is entered.

daveVk

5:42 am on Oct 30, 2012 (gmt 0)

WebmasterWorld Senior Member 10+ Year Member



try
/^[a-z]*$/

that is zero or more alphas

typomaniac

5:50 am on Oct 30, 2012 (gmt 0)

10+ Year Member Top Contributors Of The Month



Thank you so much daveVk--that hit the nail on the head. Now I can sleep--been messing with this thing for hours since before the 1st post.