I freely admit i don't get regular expressions, i can never seem to get them just right, any chance of a bit of help with this i would be great full.
I have this code, which i have taken from a couple of sources, i need to check that anthing in a text box does not include such things as * $ # | etc, but does allow % & @
<!-- Begin
var mikExp = ("[\"#+'/;<>\\]+","g");
function valitext(val) {
var strPass = val;
var strLength = strPass.length;
var lchar = val.charAt((strLength) - 1);
if(lchar.search(mikExp) != -1) {
var tst = val.substring(0, (strLength) - 1);
val = tst;
doanothercheck(val)
}
}
function doanothercheck(val) {
if(val.length < 1) {
alert("Please enter something.");
return false;
}
if(val.search(mikExp) == -1) {
return false;
}
else {
alert("Sorry, but the following characters\n\r\n\r $ % ^ * # ( ) [ ] \\ { + } ` ~ = | \n\r\n\rare not allowed!\n");
myForm.message2.select();
myForm.message2.focus();
return false;
}
return false;
}
// End -->
For some reason it just ignores whatever you add and doesnt error, been fighting with this on and off all day and it has totally stumped me why it doesn't work.
Cheers
Didn't anyone ever tell you? There's one thing you never put in a trap — if you're smart, if you value your continued existence, if you have any plans about seeing tomorrow — there's one thing you never — ever, put in a trap. … Me.
I have this code, which i have taken from a couple of sources, i need to check that anthing in a text box does not include such things as * $ # | etc, but does allow % & @
<!-- Begin
var mikExp = ("[\"#+'/;<>\\]+","g");
function valitext(val) {
var strPass = val;
var strLength = strPass.length;
var lchar = val.charAt((strLength) - 1);
if(lchar.search(mikExp) != -1) {
var tst = val.substring(0, (strLength) - 1);
val = tst;
doanothercheck(val)
}
}
function doanothercheck(val) {
if(val.length < 1) {
alert("Please enter something.");
return false;
}
if(val.search(mikExp) == -1) {
return false;
}
else {
alert("Sorry, but the following characters\n\r\n\r $ % ^ * # ( ) [ ] \\ { + } ` ~ = | \n\r\n\rare not allowed!\n");
myForm.message2.select();
myForm.message2.focus();
return false;
}
return false;
}
// End -->
For some reason it just ignores whatever you add and doesnt error, been fighting with this on and off all day and it has totally stumped me why it doesn't work.
Cheers
Didn't anyone ever tell you? There's one thing you never put in a trap — if you're smart, if you value your continued existence, if you have any plans about seeing tomorrow — there's one thing you never — ever, put in a trap. … Me.