Hello and welcome to our community! Is this your first visit?
Register
Enjoy an ad free experience by logging in. Not a member yet? Register.
Results 1 to 12 of 12
  1. #1
    New to the CF scene
    Join Date
    Dec 2012
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    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

  • #2
    Senior Coder
    Join Date
    Dec 2010
    Posts
    2,355
    Thanks
    11
    Thanked 558 Times in 551 Posts
    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.

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #4
    Master Coder felgall's Avatar
    Join Date
    Sep 2005
    Location
    Sydney, Australia
    Posts
    6,465
    Thanks
    0
    Thanked 634 Times in 624 Posts
    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/

    Don't forget to start your JavaScript code with "use strict"; which makes it easier to find errors in your code.

  • #5
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    @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

  • #6
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #7
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #8
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    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".

  • #9
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #10
    New Coder
    Join Date
    Dec 2012
    Location
    Ingerlund
    Posts
    66
    Thanks
    8
    Thanked 4 Times in 4 Posts
    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...

  • #11
    Senior Coder
    Join Date
    Apr 2011
    Location
    London, England
    Posts
    2,120
    Thanks
    15
    Thanked 354 Times in 353 Posts
    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

  • #12
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,731
    Thanks
    202
    Thanked 2,508 Times in 2,486 Posts
    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.


  •  

    Posting Permissions

    • You may not post new threads
    • You may not post replies
    • You may not post attachments
    • You may not edit your posts
    •