| « A Bit Off Kilter | The Automated Interview, The Denny's Interview, & Missing CDL TLA » |
Clean data makes me smile.
No really! When I have a finite number of brain cycles to dedicate to some process that receives user data, it makes me quite the happy guy knowing that it has been pre-scrubbed for such nasties as newline characters, the occasional ☺, or worse, the dreaded ಠ_ಠ.
Brion sent in this function which is supposed to prevent users from entering unclean text into a "thank you note" text area on a professional recognition site. Now, before bashing the function for it's curious name, I must say that it does indeed work at filtering out a bunch of characters that the original developer thought would cause an issue.
function numbersonly(myfield, e, dec)
{
var key;
var keychar;
if (window.event)
key = window.event.keyCode;
else if (e)
key = e.which;
else
return true;
keychar = String.fromCharCode(key);
// control keys
if ((key==null) || (key==0) || (key==8) ||
(key==9) || (key==13) || (key==27) )
return true;
// numbers
else if ((("0123456789ABCDEFGHIJKLMNOPQRSTUVWXYZa" +
"bcdefghijklmnopqrstuvwxyz.,-/?!$ ").indexOf(keychar) > -1))
return true;
// decimal point jump
else if (dec && (keychar == "."))
{
myfield.form.elements[dec].focus();
return false;
}
else
return false;
}
Thank goodness everybody always runs JavaScript.
Re: Thank You for Enabling JavaScript!
2009-12-09 09:29
•
by
Forumtroll
(unregistered)
|
|
This allmost beats the Regex pattern (as seen on our intranet website):
Regex reg = new Regex(@"^\K*$"); if(reg.IsMatch(txtPStrField13.Text)) pfuncInformUser(txtPStreField13); I am not sure what is the most abrasive to my eyes and mind, be it the hillarious regex, or the mindraping abuse of several notations blended into one. The worst of it is, txtPStrField13 is hidden by hardcode. CAPTCHA: conventio! Is is at convent or IO or both? |
|
I:APOSTROPHE:ve had the misfortune to have to fill in a problem:HYPHEN:description form for a :OPENBRACKET:major:CLOSEBRACKET: consumer hardware manufacturer that, while asking for a complete report on why I wanted them to repair my laptop, forbade :OPENBRACKET:server:HYPHEN:side:CLOSEBRACKET: almost all non:HYPHEN:alphanumerics :DASH: the procedure was apparently just to keep removing characters until it stopped giving :QUOTE:Illegal character:QUOTE: errors. Is this typical:QUESTIONMARK:
|
| « A Bit Off Kilter | The Automated Interview, The Denny's Interview, & Missing CDL TLA » |