To register for an Internet.com membership to receive newsletters and white papers, use the Register button ABOVE.
To participate in the message forums BELOW, click here
VBForums  

VB Wire News
Part 10 of the Visual Basic .NET 2010 Express Tutorial Complete!
How to Use the Visual Studio Code Analysis Tool FxCop
Article :: Interview with Andrei Alexandrescu (Part 3 of 3)
Introducing Visual Studio LightSwitch
Visual Studio LightSwitch Beta 1 is Available



Go Back   VBForums > Other Languages > XML, HTML, Javascript, Web and CSS

Reply Post New Thread
 
Thread Tools Display Modes
Old Feb 9th, 2006, 11:28 AM   #1
Ricky1
Hyperactive Member
 
Join Date: Feb 05
Posts: 300
Ricky1 is an unknown quantity at this point (<10)
Resolved Splitting and Checking for a character RESOLVED

Ok, a coursemate of mine is trying to do the following.

He has an input box where the user types their surname.

But if the user types their surname as

O'hara or Smith-taylor

then he needs to correct it, so its becomes O'Hara and Smith-Taylor.

so if the name contains a "-" or a " ' " then it needs to split it at that point and make the next character a Capital.

the code he has so far is

Code:
if (!nameSplit[0].match(lnameCheck) || !nameSplit[1].match(lnameCheck)) {
alert("Correct lname format is: Smith OR Oh-Hara")
document.forms[0].submit.disabled = true
document.forms[0].lname.focus()
return false
}
and he said has to be something with

Code:
onblur="function"
hope this is clear as i know nothing bout JavaScript my mate has no internet access at the moment.
__________________
Im Learning !!!!

Last edited by Ricky1; Feb 10th, 2006 at 11:27 AM.
Ricky1 is offline   Reply With Quote
Old Feb 9th, 2006, 12:20 PM   #2
penagate
Super Moderator
 
Join Date: Jan 05
Location: Sunny Adelaide
Posts: 12,738
penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)penagate has much to be proud of (1500+)
Re: Splitting and Checking for a character

If "match" is the string containing the surname
Code:
if (!name.match(/([A-Z][a-z]*)/) ||
    !name.match(/([A-Z][a-z]*)\-([A-Z][a-z]*)/) ||
    !name.match(/([A-Z][a-z]*)'([A-Z][a-z]*)/))
{
    alert('Your surname may be incorrectly capitalised, check the capitalisation')
}
Or similar.
penagate is offline   Reply With Quote
Old Feb 9th, 2006, 12:41 PM   #3
aconybeare
Fanatic Member
 
aconybeare's Avatar
 
Join Date: Oct 01
Location: UK
Posts: 740
aconybeare  is on a distinguished road (30+)
Re: Splitting and Checking for a character

Try this when the textbox loses focus the propercase function is called -

Code:
<html>
<head>
<title></title>
<script type="text/javascript">

Function ProperCase(obj){
	var strReturn_Value="";
	var sStr=obj.value;
	var iTemp=sStr.length;
	if(iTemp!=0){
		var UcaseNext=false;
		strReturn_Value += sStr.charAt(0).toUpperCase();
		alert(strReturn_Value);
		for(var iCounter=1;iCounter < iTemp;iCounter++){
			if(UcaseNext == True){
				strReturn_Value += sStr.charAt(iCounter).toUpperCase();
			}else{
				strReturn_Value += sStr.charAt(iCounter).toLowerCase();
			}
			var iChar=sStr.charCodeAt(iCounter);
			if(iChar == 32 || iChar == 45 || iChar == 46 || iChar == 13 || iChar == 10){
				UcaseNext=true;
			}else{
				UcaseNext=false;
			}
			if(iChar == 99 || iChar == 67){
				if(sStr.charCodeAt(iCounter-1)==77 || sStr.charCodeAt(iCounter-1)==109){
					UcaseNext=true;
				}
			}
			if(iChar == 39){
				if(iCounter >= 1){
					if(strReturn_Value.charCodeAt(iCounter-1) == 79){
						UcaseNext = true;
					}
				}
			}
		}
		obj.value=strReturn_Value;
	}else{
		obj.value=sStr;
	}
}


</script>
</head>
<body>
<form name="myFrm" id="myFrm">
<input type="text" id="txtname" name="txtname" value="harris-jones" onblur="ProperCase(this);">

</form>
</body>
</html>
aconybeare is offline   Reply With Quote
Reply

Go Back   VBForums > Other Languages > XML, HTML, Javascript, Web and CSS


Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)
 
Thread Tools
Display Modes

Posting Rules
You may not post new threads
You may not post replies
You may not post attachments
You may not edit your posts

BB code is On
Smilies are On
[IMG] code is On
HTML code is Off

Forum Jump


All times are GMT -5. The time now is 05:04 AM.





Acceptable Use Policy

Internet.com
The Network for Technology Professionals

Search:

About Internet.com

Legal Notices, Licensing, Permissions, Privacy Policy.
Advertise | Newsletters | E-mail Offers

Powered by vBulletin® Version 3.8.1
Copyright ©2000 - 2010, Jelsoft Enterprises Ltd.