JavaScript Development
 
Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
User Name:
Password:
Remember me

The Shed is going Social! Join us on FaceBook and Twitter and chime in on the conversation.

Go Back   Dev Shed ForumsWeb DesignJavaScript Development

Reply
Add This Thread To:
  Del.icio.us   Digg   Google   Spurl   Blink   Furl   Simpy   Y! MyWeb 
Thread Tools Search this Thread Rate Thread Display Modes
 
Unread Dev Shed Forums Sponsor:
  #1  
Old November 16th, 2012, 07:24 PM
atta_akbar atta_akbar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 atta_akbar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 28 sec
Reputation Power: 0
Other - Regex problem

Hello brothers, how are you all??
i am writing regex of two fields, i want my code to be more reducible. can i write them in one if condition. Or if there is any other way?

Code:
function fstnreg() 
<input type="text" id="fname" size="22" value="First" onKeyPress="fstnreg();" onFocus="fnfocus();" onBlur="fnblur();"/>	
					<input type="text" id="lname" size="22" value="Last" onKeyPress="lstnreg();"/>


{ 	var fstname=document.getElementById('fname').value; 	var lstname=document.getElementById('lname').value; 	var frg=/^([a-zA-Z])/; 	if(!fstname.match(frg)||!lstname.match(lrg)) 	{ 		document.getElementById('fnvali').innerHTML='Invalid name'; 		document.getElementById('fnvali').style.Color='red'; 	}  }

Reply With Quote
  #2  
Old November 16th, 2012, 07:25 PM
atta_akbar atta_akbar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 atta_akbar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 28 sec
Reputation Power: 0
Regex problem

Hello brothers, how are you all??
i am writing regex of two fields, i want my code to be more reducible. can i write them in one if condition. Or if there is any other way?

Code:
 
<input type="text" id="fname" size="22" value="First" onKeyPress="fstnreg();" onFocus="fnfocus();" onBlur="fnblur();"/>	
<input type="text" id="lname" size="22" value="Last" onKeyPress="lstnreg();"/>

function fstnreg()
{ 	
var fstname=document.getElementById('fname').value; 	
var lstname=document.getElementById('lname').value; 	
var frg=/^([a-zA-Z])/; 	if(!fstname.match(frg)||!lstname.match(lrg)) 	
{ 
document.getElementById('fnvali').innerHTML='Invalidname'; 		
document.getElementById('fnvali').style.Color='red'; 
	}
  }

Reply With Quote
  #3  
Old November 16th, 2012, 07:55 PM
Jacques1's Avatar
Jacques1 Jacques1 is online now
pollyanna
Dev Shed Regular (2000 - 2499 posts)
 
Join Date: Jul 2012
Location: Germany
Posts: 2,033 Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level)Jacques1 User rank is Lieutenant General (80000 - 90000 Reputation Level) 
Time spent in forums: 1 Month 2 Weeks 6 Days 19 h 59 m 18 sec
Reputation Power: 812
Hi,

um, don't you already have the two checks in one "if" statement?

But I think the problem is that your functions are far too specific. Writing a function for "blur the element #fname" makes no sense. Define a general function blur() and refer to the current element via "this".

Reply With Quote
  #4  
Old November 17th, 2012, 06:43 AM
atta_akbar atta_akbar is offline
Registered User
Dev Shed Newbie (0 - 499 posts)
 
Join Date: Nov 2012
Posts: 9 atta_akbar User rank is Just a Lowly Private (1 - 20 Reputation Level) 
Time spent in forums: 2 h 41 m 28 sec
Reputation Power: 0
Regex Problem.

Thanks buddy.but unfortunately the thing that i know about 'this' keyword after searching a lot is "when we use this keyword in a function and call that function on any event in an <input> tag then 'this' keyword points toward that <input> tag".
So please tell me how to use it briefly.

Quote:
Originally Posted by Jacques1
Hi,

um, don't you already have the two checks in one "if" statement?

But I think the problem is that your functions are far too specific. Writing a function for "blur the element #fname" makes no sense. Define a general function blur() and refer to the current element via "this".

Reply With Quote
Reply

Viewing: Dev Shed ForumsWeb DesignJavaScript Development > Other - Regex problem (form validation)

Developer Shed Advertisers and Affiliates



Thread Tools  Search this Thread 
Search this Thread:

Advanced Search
Display Modes  Rate This Thread 
Rate This Thread:


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

vB code is On
Smilies are On
[IMG] code is On
HTML code is Off
View Your Warnings | New Posts | Latest News | Latest Threads | Shoutbox
Forum Jump

Forums: » Register « |  User CP |  Games |  Calendar |  Members |  FAQs |  Sitemap |  Support | 
  
 


Powered by: vBulletin Version 3.0.5
Copyright ©2000 - 2013, Jelsoft Enterprises Ltd.

© 2003-2013 by Developer Shed. All rights reserved. DS Cluster - Follow our Sitemap