Hi,
I am pretty new to Javascript and wondered if someone here might be able to help....
I need to strip out all illegal characters from a text string entered into an input box. Currently the illegal chars we want to remove are hardcoded, but I want to change it so we specify which characters are allowed: A - Z. 0 - 9. This way we won't need to hardcode every possible illegal char possible!
Here is my current code for removing commas and full stops from a text string 'val_txt_list':
I have spent a long time searching the net for what I would have thought would be a well practiced method but haven't found anything good yet.
Any help greatly appreciated
I am pretty new to Javascript and wondered if someone here might be able to help....
I need to strip out all illegal characters from a text string entered into an input box. Currently the illegal chars we want to remove are hardcoded, but I want to change it so we specify which characters are allowed: A - Z. 0 - 9. This way we won't need to hardcode every possible illegal char possible!
Here is my current code for removing commas and full stops from a text string 'val_txt_list':
Code:
for(i=0; i<val_txt_list.length; i++){
if(val_txt_list.indexOf(",") > -1){
val_txt_list=val_txt_list.replace(",","")
}
if(val_txt_list.indexOf(".") > -1){
val_txt_list=val_txt_list.replace(".","")
}
}
I have spent a long time searching the net for what I would have thought would be a well practiced method but haven't found anything good yet.
Any help greatly appreciated
