homepage Welcome to WebmasterWorld Guest from 23.20.149.27
register, free tools, login, search, subscribe, help, library, announcements, recent posts, open posts,
Subscribe to WebmasterWorld
Visit PubCon.com
Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
Forum Library, Charter, Moderator: open

JavaScript and AJAX Forum

    
Spry Modification
Spry Modification
typomaniac




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

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




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

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




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

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




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

Ah, good catch. Nice modification. :)

typomaniac




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

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




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

try
/^[a-z]*$/

that is zero or more alphas

typomaniac




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

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.

Global Options:
 top home search open messages active posts  
 

Home / Forums Index / Code, Content, and Presentation / JavaScript and AJAX
rss feed

All trademarks and copyrights held by respective owners. Member comments are owned by the poster.
Terms of Service ¦ Privacy Policy ¦ Report Problem ¦ About
© Webmaster World 1996-2014 all rights reserved