I have a text box and I want to have a fucntion that if the first character is T and the next character is a number then replace the T with a space and then trim the space...
Ex: Text box= T1455
Result: (no space)1455
Printable View
I have a text box and I want to have a fucntion that if the first character is T and the next character is a number then replace the T with a space and then trim the space...
Ex: Text box= T1455
Result: (no space)1455
Use RegEx to do your replacing.
You can use [T][0-9] as your regex string, and if a match occurs, you do the replace the T.
Something like
if stringname.match("[T][0-9]")
{
//remove first letter
}
This should work:
HTML Code:<html>
<head>
<title>String Fun</title>
<script type = "text/javascript">
function trimString(s){
var len = s.length;
if(s.match(/^(T|t){1}\d+$/)){
frmMain.txtString.value = s.substring(1,len);
}
}
</script>
</head>
<body>
<form ID = "frmMain">
<input type = "text" ID = "txtString" value = "" />
<input type = "button" value = "Trim" onclick = "trimString(txtString.value);" />
</form>
</body>
</html>