User Name Password Register
DaniWeb IT Discussion Community
All
What is DaniWeb IT Discussion Community?
You're currently browsing the JavaScript / DHTML / AJAX section within the Web Development category of DaniWeb, a massive community of 425,900 software developers, web developers, Internet marketers, and tech gurus who are all enthusiastic about making contacts, networking, and learning from each other. In fact, there are 1,934 IT professionals currently interacting right now! Registration is free, only takes a minute and lets you enjoy all of the interactive features of the site.
Please support our JavaScript / DHTML / AJAX advertiser: Lunarpages Web Hosting
Views: 720 | Replies: 2 | Solved
Reply
Join Date: Jun 2008
Posts: 8
Reputation: darkraider is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
darkraider darkraider is offline Offline
Newbie Poster

How to set only Letter and space

  #1  
Jun 30th, 2008
How to i get it rite ?? i tried the code below by it fail, anyone can correct me and tell when i when wrong ??

var Fname=document.getElementById('Fname').value;
if(!/^[A-z]*$/+$/.test(Fname)){
msg+='- Only Letter & Space '+email+'\n\n';}
AddThis Social Bookmark Button
Reply With Quote  
Join Date: Jun 2006
Location: India
Posts: 6,855
Reputation: ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold ~s.o.s~ is a splendid one to behold 
Rep Power: 23
Solved Threads: 344
Moderator
Featured Poster
~s.o.s~'s Avatar
~s.o.s~ ~s.o.s~ is offline Offline
Lazy, Useless & Apathetic

Re: How to set only Letter and space

  #2  
Jul 2nd, 2008
The RegExp you have there is incorrect. The correct one would be:
/*
For Letters: [a-zA-Z] (dealing with both upper and lower case characters)
For Space: [ ]
Putting them together: [a-zA-Z ]+
Use a + instead of * since a blank string is not a valid letter nor a space.
Use ^ and $ since our string should start and end with the given pattern.
*/
var myStr = "hello";
if(/^[a-zA-Z ]+$/.test(myStr) {
  window.alert("String contains only alphabets and spaces");
} else {
  window.alert("String doesn't contain only alphabets and spaces");
}
I don't accept change. I don't deserve to live.

Happiness corrupts people.

Failing to value the lives of others cheapens your own.
Reply With Quote  
Join Date: Jun 2008
Posts: 8
Reputation: darkraider is an unknown quantity at this point 
Rep Power: 0
Solved Threads: 0
darkraider darkraider is offline Offline
Newbie Poster

Re: How to set only Letter and space

  #3  
Jul 2nd, 2008
ok will go try it out thk man
Reply With Quote  
Reply

Only community members can participate in forum threads. You must register or log in to contribute.

DaniWeb JavaScript / DHTML / AJAX Marketplace
Currently Active Users Viewing This Thread: 1 (0 members and 1 guests)

 

Thread Tools Display Modes

Similar Threads
Other Threads in the JavaScript / DHTML / AJAX Forum

All times are GMT -4. The time now is 7:38 pm.
Forum system based on vBulletin Copyright ©2000 - 2008, Jelsoft Enterprises Ltd.
©2003 - 2008 DaniWeb® LLC