Text box validation using regular expression

Posted by Sreenuksr under JavaScript on 10/19/2011 | Points: 10 | Views : 5942 | Status : [Member] | Replies : 1
I have a textbox and have to use the regular expressions in asp.net

my text should not allow the spaces in first and last place.

output should be:

India Bangalore -valid

<space>India Bangalore<space> - not valid

i.e : use can enter the spaces in between the words but not in first position and last position.

If you have solution in java script that also fine.

Thanks in advance.


Posted by: Abdulhaknet on: 10/27/2011 [Member] Starter | Points: 25

Hi sreenu,

please go through the code below it allow alphabets, numbers and special charecters, and it will not allow space begin and end of the string

Please check it.

<SCRIPT LANGUAGE = "JavaScript1.2">
re = /^\s+|\s+$/g;
function testInfo(id) {
var str = document.getElementById(id).value;

Enter your phone number (with area code) and then press Enter.
Old Text
<INPUT TYPE="text" NAME="Phone" id="m1" onChange="testInfo(this.id);">
New Text
<INPUT TYPE="text" NAME="NPhone" id="m2" onChange="testInfo(this.id);">

Sreenuksr, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response