/    Sign up×
Community /Pin to ProfileBookmark

regular expression space problem?

I have 2 text boxes.i have enter without space in the first text box, the second text box will allow to enter characters.but i entered with space in then first text box the second textbox doesnot allow any charcters? any help?

<!DOCTYPE HTML PUBLIC “-//W3C//DTD HTML 4.01 Transitional//EN”>
<html>
<head>
<script language=javascript>
function validatePhone(obj)

{

var testVar = document.getElementById(obj).value;
var objRegExp = /^[a-zA-Z]*$/;
//var objRegExp = /(^[a-zA-Z]([a-z_.]*)@([a-z_.]*
)([.][a-z]{3})$)|(^[a-z]([a-z_.]*)@([a-z_.]*)(.[a-z]{3})(.[a-z]{2})*$)/i;
var objRegExp = /^[a-zA-Z]*$/;

//var objRegExp = /^[‘ ‘]*$/;
// accept only 10 digit value 1234567890
if(!objRegExp.test(testVar))
{

document.getElementById(obj).focus();
}

}

</script>

<title>Untitled Document</title>
<meta http-equiv=”Content-Type” content=”text/html; charset=iso-8859-1″>
</head>

<body>
<table width=”100%” border=”0″ cellPadding=”1″ cellSpacing=”1″>
<TBODY>
<tr>
<td height=”20″><font size=”1″>
<input name=”newreason” type=”Text” size=”20″ onBlur=”validatePhone(‘newreason’);”>
</font></td>
<td height=”20″ nowrap=”true”> <p><font face=”Verdana” size=”1″><b><font face=”Verdana, Arial, Helvetica, sans-serif” size=”1″>
</font><font face=”Verdana” size=”1″><b><font face=”Verdana, Arial, Helvetica, sans-serif” size=”1″>
<input name=”newholidaydate” type=”text” id=”test10″ value=”” size=”20″>
</font></b></font><font face=”Verdana, Arial, Helvetica, sans-serif” size=”1″>
<strong><font size=”1″ face=”Verdana, Arial, Helvetica, sans-serif”>
</font></strong></font></b></font></td>
</tr>
</TBODY>
</table>
</body>
</html>

to post a comment
JavaScript

1 Comments(s)

Copy linkTweet thisAlerts:
@ExuroFeb 22.2005 — Your first textbox keeps getting the focus because it's still invalid. You need to delete that space that's sitting in there before it'll let you move focus to a different form element. However, since it's just a space, it's hard to see that there's still anything entered there at all. So, it might be better to trim the whitespace off the field every time it validates:
function validatePhone(obj)
{
// Trim off the extra whitespace
document.getElementById(obj).value = document.getElementById(obj).value.replace(/^s*(S*)s*$/,"$1");
// Continue on with the rest of the function as you had it
var testVar = document.getElementById(obj).value;
×

Success!

Help @gmmsk7 spread the word by sharing this article on Twitter...

Tweet This
Sign in
Forgot password?
Sign in with TwitchSign in with GithubCreate Account
about: ({
version: 0.1.9 BETA 4.27,
whats_new: community page,
up_next: more Davinci•003 tasks,
coming_soon: events calendar,
social: @webDeveloperHQ
});

legal: ({
terms: of use,
privacy: policy
});
changelog: (
version: 0.1.9,
notes: added community page

version: 0.1.8,
notes: added Davinci•003

version: 0.1.7,
notes: upvote answers to bounties

version: 0.1.6,
notes: article editor refresh
)...
recent_tips: (
tipper: @Yussuf4331,
tipped: article
amount: 1000 SATS,

tipper: @darkwebsites540,
tipped: article
amount: 10 SATS,

tipper: @Samric24,
tipped: article
amount: 1000 SATS,
)...