View Full Version : validation "Letters not allowed"
tobijas20
April 27th, 2005, 09:55 AM
How to specify in this validation script that letters are not allowed?
on (release) {
if (Number(_parent.box) < 1 || Number(_parent.box) > 12) {
_parent.worning.gotoAndStop(2);
} else {
_parent.worning.gotoAndStop(1);
_parent.gotoAndPlay(2);
}
}
box is a text field.
osc23
April 27th, 2005, 10:12 AM
var str = _parent.box.text;
var test = false;
//ignore the last character in the string cos its an escape character
for (var i = str.length-1; i>=0; i--){
trace (Number(str.charAt(i))+" "+str.charAt(i));
if (isNaN(Number(str.charAt(i))) == true){
test = true;
break;
}
}
if (test == true){
_parent.worning.gotoAndStop(2);
} else {
_parent.worning.gotoAndStop(1);
_parent.gotoAndPlay(2);
}
}
tobijas20
April 27th, 2005, 10:56 AM
Thank you! I will test it now :)
tobijas20
April 28th, 2005, 05:30 AM
Nope, it doesn't work. I have put this code in the same frame as "myButton":
var str = _parent.box.text;
var test = false;
//ignore the last character in the string cos its an escape character
for (var i = str.length-1; i>=0; i--){
trace (Number(str.charAt(i))+" "+str.charAt(i));
if (isNaN(Number(str.charAt(i))) == true){
test = true;
break;
}
}
myButtun.onRelease = function(){
if (test == true){
_parent.worning.gotoAndStop(2);
} else {
_parent.worning.gotoAndStop(1);
_parent.gotoAndPlay(2);
}
}
But it seams like whatever I write in the box (letters or numbers) it allows to submit!
osc23
April 28th, 2005, 06:35 AM
Try putting all the code inside the onRelease function. I presume you only want to test what's in the box when the button is pressed.
myButton.onRelease = function(){
var str = _parent.box.text;
var test = false;
//ignore the last character in the string cos its an escape character
for (var i = str.length-1; i>=0; i--){
trace (Number(str.charAt(i))+" "+str.charAt(i));
if (isNaN(Number(str.charAt(i))) == true){
test = true;
break;
}
}
if (test == true){
_parent.worning.gotoAndStop(2);
} else {
_parent.worning.gotoAndStop(1);
_parent.gotoAndPlay(2);
}
}
tobijas20
April 28th, 2005, 10:36 AM
Nope, still not working. Whatever I type, "test" is always "false" and the animation goes!
But I have made this: I have put the mask over it and embeded ony "0123456789", so noone can type anything else ;)
And I have put just a regular check to disable "0" and "empty" -
if(Number(box) <1 || !box.length)
:)
osc23
April 28th, 2005, 10:38 AM
Fair enough. ;)
I reckon that _parent reference should be _root or _level0 though
Powered by vBulletin® Version 4.1.10 Copyright © 2012 vBulletin Solutions, Inc. All rights reserved.