Go Back   CodingForums.com > :: Client side development > JavaScript programming

Before you post, read our: Rules & Posting Guidelines

Reply
 
Thread Tools Rate Thread
Enjoy an ad free experience by logging in. Not a member yet? Register.
Old 12-18-2012, 04:19 PM   PM User | #1
roberto222
New to the CF scene

 
Join Date: Dec 2012
Posts: 1
Thanks: 0
Thanked 0 Times in 0 Posts
roberto222 is an unknown quantity at this point
Help with vaildation

Can anyone show me, how to do this ?

Make a form for data entry. On the form will be at the following information: name, address and registration number.

Add validation controls on the form, so that the user can only enter the appropriate data (name and surname only letters in the mail just mail in the registration number of digits only).

Thanxxxxx
roberto222 is offline   Reply With Quote
Old 12-18-2012, 06:03 PM   PM User | #2
devnull69
Senior Coder

 
Join Date: Dec 2010
Posts: 2,261
Thanks: 10
Thanked 533 Times in 527 Posts
devnull69 will become famous soon enough
This is not a free coding service. Please show us your code and we will help you with specific problems if you describe them sufficiently.
devnull69 is offline   Reply With Quote
Old 12-18-2012, 06:30 PM   PM User | #3
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
If you're not using jQuery (which you don't need for something like this), then each form element would be referred to by document.forms["formname"].elementName. Depending upon what kind of element it is (input text, input radio, input checkbox, select, textarea, etc.) the value can be referenced in different ways.

Input text or textarea: document.forms["formname"].textInputID.value.

Input radio/checkbox: document.forms["formname"].inputID[index] where index is the zero-based position of which element is checked.

Select: document.forms["formname"].selectID.value or document.forms["formname"].selectID.selectedIndex to get the position of the selected option.

For text and textarea, you can't just check for a blank value "", because even just one space (and just a space) will bypass the validation. You can use RegEx, but I suspect that you aren't familiar with it. Best to use prototype to give the JS a trim function:

Code:
if(!String.prototype.trim){ String.prototype.trim = function(){ return this.replace(/^\s+|\s+$/,''); } }

if(document.forms"formname"]textInputID.value.trim() == "") // Trim the value and check for anything.. if not, it's not valid
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 12-18-2012, 06:38 PM   PM User | #4
felgall
Master Coder

 
felgall's Avatar
 
Join Date: Sep 2005
Location: Sydney, Australia
Posts: 5,530
Thanks: 0
Thanked 503 Times in 494 Posts
felgall is a jewel in the roughfelgall is a jewel in the roughfelgall is a jewel in the rough
Quote:
Originally Posted by WolfShade View Post
If you're not using jQuery (which you don't need for something like this), then each form element would be referred to by document.forms["formname"].elementName.
That's the prehistoric way of doing it. Since each form field needs an id to attach its label you may as well reference them using document.getElementById just as for any element with an id.
__________________
Stephen
Learn Modern JavaScript - http://javascriptexample.net/
Helping others to solve their computer problem at http://www.felgall.com/
felgall is offline   Reply With Quote
Old 12-18-2012, 07:31 PM   PM User | #5
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
@Wolfshade your regex for the trim requires the global modifier (g) to remove spaces at the end of the text as well as the beginning:

Code:
return this.replace(/^\s+|\s+$/g,'')
I like my/this version which behaves like Excel's TRIM function; that is, collapsing spaces between words:
Code:
if (!String.prototype.trim) {
    String.prototype.trim = function () {
        var s = this.replace(/^\s+|\s+$/g,"");
        return s.replace(/\s+/g," ");
}
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-18-2012, 08:23 PM   PM User | #6
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
Quote:
Originally Posted by AndrewGSW View Post
@Wolfshade your regex for the trim requires the global modifier (g) to remove spaces at the end of the text as well as the beginning:

Code:
return this.replace(/^\s+|\s+$/g,'')
Not to hijack the thread, but why use the global flag if I'm using ^ and $ ? I thought by explicitly stating /^ start of string, and $/ end of string, that would replace all beginning and ending whitespace with nothing.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 12-18-2012, 08:52 PM   PM User | #7
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Not to hijack the thread, but why use the global flag if I'm using ^ and $ ? I thought by explicitly stating /^ start of string, and $/ end of string, that would replace all beginning and ending whitespace with nothing.
Without the g-global modifer it will replace spaces either at the beginning or the end, but not both. That is, if the spaces are at the beginning, it will replace these but not continue to examine the rest of the string. The pipe separator | means or. The global modifier means "don't stop!".
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-18-2012, 09:03 PM   PM User | #8
WolfShade
Regular Coder

 
Join Date: Apr 2012
Location: St. Louis, MO, USA
Posts: 960
Thanks: 7
Thanked 100 Times in 100 Posts
WolfShade is an unknown quantity at this point
Ah.. understood. Thanks for the clarification.
__________________
^_^

If anyone knows of a website that can offer ColdFusion help that isn't controlled by neurotic, pedantic jerks* (stackoverflow.com), please PM me with a link.
*
The neurotic, pedantic jerks are not the owners; just the people who are in control of the "popularity contest".
WolfShade is offline   Reply With Quote
Old 12-18-2012, 10:26 PM   PM User | #9
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by WolfShade View Post
Ah.. understood. Thanks for the clarification.
I am here to clarify
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-18-2012, 10:33 PM   PM User | #10
Entity_
New Coder

 
Join Date: Dec 2012
Location: Ingerlund
Posts: 63
Thanks: 8
Thanked 4 Times in 4 Posts
Entity_ is an unknown quantity at this point
They're never gonna learn everything if you guys are this kind... I'd take a leaf out of devnull's book XDXD

Not only that, but surely you could be charging money for what is essentially him asking you to do a coding task for him, not spot the errors?


meh i dunno... I've only been here two days!

Last edited by Entity_; 12-18-2012 at 10:37 PM.. Reason: thought of mentioning something else...
Entity_ is offline   Reply With Quote
Old 12-18-2012, 10:43 PM   PM User | #11
AndrewGSW
Senior Coder

 
Join Date: Apr 2011
Location: London, England
Posts: 2,120
Thanks: 15
Thanked 354 Times in 353 Posts
AndrewGSW will become famous soon enough
Quote:
Originally Posted by Entity_ View Post
They're never gonna learn everything if you guys are this kind... I'd take a leaf out of devnull's book XDXD

Not only that, but surely you could be charging money for what is essentially him asking you to do a coding task for him, not spot the errors?

meh i dunno... I've only been here two days!
We haven't provided the full code that the OP was seeking and he won't be able to make use of the information we have provided (during our discussion) without putting in a substantial effort himself.

Personally, I rarely supply full code unless I can see that the OP is putting in (or has made..) some effort (usually over the course of a few posts) and/or it is something that interests me
__________________
"I'm here to save your life. But if I'm going to do that, I'll need total uninanonynymity." Me Myself & Irene.
Validate your HTML and CSS
AndrewGSW is offline   Reply With Quote
Old 12-19-2012, 07:22 AM   PM User | #12
Philip M
Supreme Master coder!

 
Philip M's Avatar
 
Join Date: Jun 2002
Location: London, England
Posts: 17,102
Thanks: 197
Thanked 2,421 Times in 2,399 Posts
Philip M has a spectacular aura aboutPhilip M has a spectacular aura aboutPhilip M has a spectacular aura about
Quote:
Originally Posted by roberto222 View Post
Can anyone show me, how to do this ?

Make a form for data entry. On the form will be at the following information: name, address and registration number.

Add validation controls on the form, so that the user can only enter the appropriate data (name and surname only letters in the mail just mail in the registration number of digits only).

Thanxxxxx
Form validation has been covered very many times in this forum. Have you tried using the search feature?
__________________

All the code given in this post has been tested and is intended to address the question asked.
Unless stated otherwise it is not just a demonstration.
Philip M is offline   Reply With Quote
Reply

Bookmarks

Jump To Top of Thread


Thread Tools
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

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

Forum Jump


All times are GMT +1. The time now is 02:48 PM.


Advertisement
Log in to turn off these ads.