|
-
Apr 7th, 2005, 09:30 PM
#1
Thread Starter
Fanatic Member
Replace First Character in text box
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
-
Apr 8th, 2005, 01:42 AM
#2
Re: Replace First Character in text box
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
}
-
Apr 8th, 2005, 06:24 AM
#3
Fanatic Member
Re: Replace First Character in text box
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>
Posting Permissions
- You may not post new threads
- You may not post replies
- You may not post attachments
- You may not edit your posts
-
Forum Rules
|
Click Here to Expand Forum to Full Width
|