Hi, I am new to php and javascript. I facing the validated special character in text box. in following code is my codes. function addRowToTablesaved() { document.getElementById('btnDeleteselectedsaved').disabled =true; document.getElementById('btnDeleteallsaved').disabled =true; var tbl = document.getElementById('tblDocsaved'); var lastRow = tbl.rows.length; // if there's no header row in the table, then iteration = lastRow + 1 var iteration = lastRow; document.frmDocsaved.txtActualRowLengthsaved.value = iteration; // alert('iteration is: ' + iteration);//jamayah debug var row = tbl.insertRow(lastRow); if(lastRow%2!=0){ row.style.backgroundColor = "#85CC2B"; }else{ row.style.backgroundColor = "#D9FFBB"; } // 1 if(iteration<21){ var cell1 = row.insertCell(0); var uploadadd = document.createElement('input'); uploadadd.type = 'file'; uploadadd.name = 'userfile' + iteration; uploadadd.id = 'userfile' + iteration; uploadadd.size = 70; cell1.innerHTML = " " + iteration + ". "; cell1.appendChild(uploadadd); //2 var cell2 = row.insertCell(1); var txtCompanyname= document.createElement('input'); txtCompanyname.type = 'text'; txtCompanyname.name = 'txtFileDesc' + iteration; txtCompanyname.id = 'txtFileDesc' + iteration; txtCompanyname.size = 70; cell2.innerHTML = " "; cell2.appendChild(txtCompanyname); document.getElementById('btnAddsaved').disabled =false; document.getElementById('btnRemovesaved').disabled =false; document.getElementById('uploadsaved').disabled =false; document.getElementById('btnEditsaved').disabled =true; if(document.frmDocsaved.txtActualRowLengthsaved.value == '20'){ document.getElementById('btnAddsaved').disabled =true; } }else{ document.getElementById('btnAddsaved').disabled =true; } } For your information, i try to add onkeyup txtCompanyname.onKeyup = function() { !(/^[A-zÑñ0-9]*$/i).test(f.value)?f.value = f.value.replace(/[^A-zÑñ0-9]/ig,''):null; } but it cant work. Please write any suggestion to my problems. Thanks
hi i'm doing the validate textbox , so for those special key like !@#$%*()'" when user key in to the test box will automatic backspace. i have a button called "add" and it apply this addRowToTablesaved() javascript this button's function is addrowtable in my php . from my code , user allow to attach files and allow write the file description. When the user Key in the special key, the special character will automatic backspace. so, i try to .onkeyup to apply this validate function but it not work. thanks Rgrd fayee
I'm not going to code at one in the morning but that is a lot of code for a simple process. Here is a step through in doing what you're trying to achieve: 1. Write a function so that when the user releases the key, textbox text gets stored in a variable. 2. You use regex to match special character. 3. If match returns true remove the last character in the string. 4. Update textbox text with a new string.