Posted: Mon Sep 18, 2006 5:00 am Trouble in Validation
i need to ensure an entry in a text box.at the same I need to ensure that the entry is not in the form of spaces i.e. it needs to be some alphabets or numbers or special characters only.
I am giving the function that I invoked by onSubmit
function ensure_item()
{
if(formname.textitemname.value=="")
{alert("You must enter a value for Item");
formname.textitemname.focus();
return false;}
else return true;
}
and I simply used onSubmit="ensure_item()" in the form tag.
Now the code works as long as user types'nothing' in the test box but if he types a series of spaces the code no longer works and validation fails.
Please help...i wd really appreciate if some modifications in the code i gave are suggested.
hi,
Thaks for ur help in validation problem.Can u tell ime if I can also use 'trim' function in the same context i.e. something like
if(!Trim(formname.field.value)=="')
{
alert("alert text");
return false;
}
I tried using this but it doesn't seem to work...maybe some syntactic error because I m very new to javascript and programming in general.
Actually the reason for wanting to know this is that I think if I use Trim then even if the user enters some spaces followed by commas then the function wd work .
the solution u provided works if there are all spaces but if there is some text along with commas it still alerts the user and forces him to remove spaces which I do not want.
My intention is only to ensure that some text be ther...with or without spaces but not just spaces.
You cannot post new topics in this forum You cannot reply to topics in this forum You cannot edit your posts in this forum You cannot delete your posts in this forum You cannot vote in polls in this forum