Showing posts with label regex. Show all posts
Showing posts with label regex. Show all posts

Thursday, September 20, 2007

Restrict Alphabet Input In TextBox Using Regular Expression

<html>
<head>
<script language="javascript">
function blockChar()
{
var str = document.getElementById('txt').value;
str = str.replace(/[^\d]*/g,'');
document.getElementById('txt').value = str;
}
</script>
</head>
<body onload="javascript:document.getElementById('txt').focus();">
<input type="text" id='txt' onkeyup="blockChar();" />
</body>
</html>


Program Demo

Note:IE Supported

Wednesday, August 22, 2007

Removing The White Space In The String At The End Using Regular Expression (Right Trim)

<html>
<head>
<script language="javascript">
function Left_Trim()
{
var str = document.getElementById('txt1').value;
alert(str.length);// Alert To Show The Length Of The String Before Removing White Space
str = str.replace(/\s+$/g,'');
alert(str.length); // Alert To Show The Length Of The String After Removing White Space
document.getElementById('txt1').value = str;
document.getElementById('txt1').focus();
}
</script>
</head>
<body>
<input type='text' id='txt1' value='Click To Check ' /> <input type='button' id='bt1' value='Remove Space At End Of The String' onclick='Left_Trim();' />
</body>
</html>


Friday, August 3, 2007

Remove White Space In String Using Regular Expression in JavaScript

<html>
<head>
<script language="javascript">
function rmWhiteSpace()
{


var str = document.getElementById('txt1').value;

str = str.replace(/\s+/g,'');

document.getElementById('txt1').value = str;

// \s+ Description
// + 1 or more of previous expression.
// \s Matches any white-space character.
// Equivalent to the Unicode character categories [\f\n\r\t\v\x85\p{Z}].
// If ECMAScript-compliant behavior is specified with the ECMAScript option,
// \s is equivalent to [ \f\n\r\t\v].
}
</script>
</head>
<body>
<input type='text' id='txt1' value=' Click To Check' /> <input type='button' id='bt1' value='Remove White Space' onclick='rmWhiteSpace();' />
</body>
</html>


Program Demo

OutPut



Tuesday, June 19, 2007

C# Regular Expressions

some simple regexes for simple string processing

get filename from url (full filename)
([^\\\\]*$)

get extension from url (full filename)
(?<=\\.)([^\\\\]*$)