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 15 of 15
  1. #1
    New to the CF scene
    Join Date
    Apr 2013
    Posts
    1
    Thanks
    0
    Thanked 0 Times in 0 Posts

    Stop users typing all in Capitals Letters

    Can anyone help me.

    I am looking for a JavaScript to change a input field. I want to stop users trying to type all in Capitals Letters.

    I would like to only allow those examples.

    The Film Pool And Cinematography Workshop
    The film pool and cinematography workshop.

    I don't want the user to do this,
    THE FILM POOL AND CINEMATOGRAPHY WORKSHOP

    This is the input I want to use it with.
    <input id="m1_title" class="cms_textfield" type="text" maxlength="255" size="30" value="" name="m1_title">


    I found scripts that force all letters to lowercase or upppercase. I only want the use uppercase only start of a word if user choose so..

    Its possible to this?

    Thank you in adv.

    Andrew

  • #2
    Regular Coder
    Join Date
    Mar 2006
    Posts
    726
    Thanks
    35
    Thanked 132 Times in 123 Posts
    You can capitalize all the words with css- text-transform:capitalize,
    but if you only want to capitalize words capitalized by the user you need a bit more.

    var str= 'THE MIGHTY QUINN WAS AN ESKIMO';
    Code:
    str.replace(/([a-zA-Z])([a-zA-Z']+)/g, function(a, b, c){
    	return b+c.toLowerCase();
    });
    //RETURNS:
    The Mighty Quinn Was An Eskimo

    var str= 'THE MIGHTY QUINN was an ESKIMO';
    Code:
    str.replace(/([a-zA-Z])([a-zA-Z']+)/g, function(a, b, c){
    	return b+c.toLowerCase();
    });
    //RETURNS:
    The Mighty Quinn was an Eskimo
    Last edited by mrhoo; 04-10-2013 at 02:36 PM. Reason: added an example

  • #3
    Regular Coder
    Join Date
    Apr 2012
    Location
    St. Louis, MO
    Posts
    985
    Thanks
    7
    Thanked 101 Times in 101 Posts
    Also:
    Code:
    function toProperCase(str){
        return str.toLowerCase().replace(/^(.)|\s(.)/g, function($1){return $1.toUpperCase();});
        }
    <input id="m1_title" class="cms_textfield" type="text" maxlength="255" size="30" value="" name="m1_title" onblur="toProperCase(this.value)">
    ^_^

    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
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by WolfShade View Post
    Also:
    Code:
    function toProperCase(str){
        return str.toLowerCase().replace(/^(.)|\s(.)/g, function($1){return $1.toUpperCase();});
        }
    <input id="m1_title" class="cms_textfield" type="text" maxlength="255" size="30" value="" name="m1_title" onblur="toProperCase(this.value)">
    aside from the non-hooked-up input event, i don't think this is what the user wants:

    Code:
    toProperCase("A man, Mr. McDonald, once said, 'YEOW!' ") ;
    // == "A Man, Mr. Mcdonald, Once Said, 'yeow!' "




    this behavior is more apropos:
    Code:
    function fixCapitals(s){
     return s.replace(/([A-Z]{1})([A-Z]{1,})/g,function(w,c,w){return c + w.toLowerCase(); })
    }
    
    
    //test:
    fixCapitals("A man, Mr. McDonald, once said, 'YEOW!' ");
    //"A man, Mr. McDonald, once said, 'Yeow!' "

    html
    Code:
    <input id="m1_title" class="cms_textfield" type="text" maxlength="255" size="30" 
         value="" name="m1_title" onblur="this.value=fixCapitals(this.value)">

    edit: i just noticed my code is somewhat related to mrhoo's, but mine won't screw up McDonald - it only fixes two capitals in a row, not just two letters in a row, which also makes it much faster to execute (big whoop)...
    Last edited by rnd me; 04-10-2013 at 04:41 PM.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #5
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by andrewvideo View Post
    I only want the use uppercase only start of a word if user choose so..

    Its possible to this?
    Leave the first character on the word as is.

    Change the second to the last character in the word to lower case.

    Fairly straight forward with javascript.

  • #6
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by knightCoder View Post
    Leave the first character on the word as is.

    Change the second to the last character in the word to lower case.

    Fairly straight forward with javascript.
    Oh, is it? And your suggested code to do that is?

    Perhaps a slight mod to rnd me's code might do the trick:-

    Code:
    function fixCapitals(s) {
    return s.replace(/([A-Za-z]{1})([A-Z]{1,})/g,function(w,c,w){return c + w.toLowerCase(); })
    }
    
    var txt = (fixCapitals("A man, Mr. McDonald, once said, 'YEOW!' "));   // A man, Mr. Mcdonald, once said, 'Yeow!' 
    alert (txt);
    If you want to preserve the capital D in McDonald you could use:-

    Code:
    var txt1 = (txt.replace(/\b(m(a)?c)?(\w)(?=\w)/ig, function($1, $2, $3, $4) {
    return ($2) ? "M" + ($3 || "") + "c" + $4.toUpperCase(): $4;
    }));
    alert (txt1);
    But of course we know from previous discussions that the capital D properly only applies if the Mc or Mac (son of) precedes a proper name, and not an occupation, e.g. Macnab (son of the abbott), Maccosh (son of the footman), etc. I don't see any way to detect that except by using a specific list of names. In fact such a list would be quite short, there are only a handful in common use apart from McDonald and McLeod. Many or most Anglicised Scottish surnames drop the Mc anyway. For example, Mac a' Bhacstair (son of the baker) is nowadays almost always rendered as Baxter, and the Mac'IlleChiars have morphed into the Kerrs.

    So rthaer than anything fancy:-

    Code:
    var txt = "Macdonald Mcleod";
    txt = txt.replace(/(M(a?)c)donald/gi, "$1Donald");
    txt = txt.replace(/(M(a?)c)leod/gi, "$1Leod");
    alert (txt);
    Last edited by Philip M; 04-11-2013 at 08:39 AM.

    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.

  • #7
    Regular Coder
    Join Date
    May 2012
    Location
    France
    Posts
    224
    Thanks
    0
    Thanked 32 Times in 30 Posts
    What about a : «Please do not capitalize all letters» after two following Capitals letters ?
    Is not it better to use the user?

  • #8
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by Philip M View Post
    Oh, is it? And your suggested code to do that is?
    yep, for me it is. I don't normally provide a free coding service. If the OP returns to the thread and posts some code, I can guide them if he/she has any problems.

    If the op doesn't return I will assume they got the solution on another website.

  • #9
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by Philip M View Post
    Perhaps a slight mod to rnd me's code might do the trick:-

    Code:
    function fixCapitals(s) {
    return s.replace(/([A-Za-z]{1})([A-Z]{1,})/g,function(w,c,w){return c + w.toLowerCase(); })
    }
    
    var txt = (fixCapitals("A man, Mr. McDonald, once said, 'YEOW!' "));   // A man, Mr. Mcdonald, once said, 'Yeow!' 
    alert (txt);
    Wht don't you go and test your code before posting because the above is jibberish and nor what the OP wants.

    An input string of

    Code:
    "a MAN, Mr. Mcdonald, once said, 'YEOW!' "
    outputs the same string your alert()

    Code:
    a MAN, Mr. Mcdonald, once said, 'YEOW!'

  • #10
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    @philip_m

    your signature

    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.
    is laughable as evidenced in my previous post.

    test your code before posting otherwise you're just wasting the op's and other readers' time.

  • #11
    Supreme Master coder! Philip M's Avatar
    Join Date
    Jun 2002
    Location
    London, England
    Posts
    17,908
    Thanks
    203
    Thanked 2,531 Times in 2,509 Posts
    Quote Originally Posted by knightCoder View Post
    Wht don't you go and test your code before posting because the above is jibberish and nor what the OP wants.

    An input string of

    Code:
    "a MAN, Mr. Mcdonald, once said, 'YEOW!' "
    outputs the same string your alert()

    Code:
    a MAN, Mr. Mcdonald, once said, 'YEOW!'
    No it doesn't, Bullant, Minder and all your other usernames which are all banned for being abusive.

    fixCapitals("a MAN, Mr. McDonald, once said, 'YEOW!' ");

    results in

    a Man, Mr. McDonald, once said, 'Yeow!'

    which is what it is supposed to be, that is a capital letter at the start of a word only where the user has used a capital at the start of that word.

    Quote Originally Posted by knightCoder View Post
    Leave the first character on the word as is.
    Change the second to the last character in the word to lower case.
    No?

    Your post reported to mods for being abusive and wrong. I am taking bets that you will be kicked out of this forum yet again by the end of June. I won last time when I bet you would be gone by Christmas.

    Advice such as "Fairly straight forward with javascript" is not helpful at all, but merely serves to massage your ego and increase your post count.
    Last edited by Philip M; 04-11-2013 at 05:51 PM. Reason: Typo

    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.

  • #12
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by Philip M View Post
    which is what it is supposed to be,
    Then we have different understandings of what the op wants.

    Quote Originally Posted by Philip M View Post
    Advice such as "Fairly straight forward with javascript" is not helpful at all, but merely serves to massage your ego and increase your post count.
    I've seen Old Pedant post several times that something is trivial to code without actually posting the code for it. So if it's ok for him then it is ok for every other member.

    Quote Originally Posted by Philip M View Post
    increase your post count.
    If you go get your facts straight you will see that new members like myself who haven't been on this site before are not given Edit buttons for their posts (have a look in the Feedback forum).

    In any case, this thread is moot now because the solution to the OP's request is on another webiste and so the OP most probably has their solution now which is the most likely explanation as to why they haven't returned.

  • #13
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by knightCoder View Post
    In any case, this thread is moot now because the solution to the OP's request is on another webiste and so the OP most probably has their solution now which is the most likely explanation as to why they haven't returned.
    or he got scared away.

    why does everything have to turn into an argument with you?
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%

  • #14
    Banned
    Join Date
    Mar 2013
    Posts
    139
    Thanks
    0
    Thanked 9 Times in 9 Posts
    Quote Originally Posted by rnd me View Post
    or he got scared away.

    why does everything have to turn into an argument with you?
    @daniel davis (ref: whois.com)

    perhaps he did scared away. I don't know why. I'm pretty sure he's got the solution to his request on the other website by now .

    I'm not arguing at all. I'm not doing anything illegal and I haven't broken any forum rules.

    Don't hijack this thread onto whatever issue you might have with me. If you want to discuss further I, or my legal reps, will email my responses to the email address on your whois.com record.

  • #15
    Senior Coder rnd me's Avatar
    Join Date
    Jun 2007
    Location
    Urbana
    Posts
    4,292
    Thanks
    10
    Thanked 583 Times in 564 Posts
    Quote Originally Posted by rnd me View Post
    or he got scared away.

    why does everything have to turn into an argument with you?

    Quote Originally Posted by knightCoder View Post
    @daniel davis (ref: whois.com)

    perhaps he did scared away. I don't know why. I'm pretty sure he's got the solution to his request on the other website by now .

    I'm not arguing at all. I'm not doing anything illegal and I haven't broken any forum rules.

    Don't hijack this thread onto whatever issue you might have with me. If you want to discuss further I, or my legal reps, will email my responses to the email address on your whois.com record.
    lol!
    totally classic. i wish this site has better print css, this is a keeper!
    you write much better dry wit than js, if that's what you're going for.
    im still chuckling as i write this.

    i don't care what everyone says about you, you're alright with me kiddo.

    @all:
    knightCoder is not an over-reacting baby-face coder, he's a middle-aged former screen-writer with lots of time and a strange sense of humor.
    my site (updated 13/9/26)
    BROWSER STATS [% share] (2014/5/28) IE7:0.1, IE8:5.3, IE11:8.4, IE9:3.2, IE10:3.2, FF:18.2, CH:46, SF:7.9, NON-MOUSE:32%


  •  

    Posting Permissions

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