Showing posts with label javascript. Show all posts
Showing posts with label javascript. Show all posts

Thursday, August 25, 2016

Check if string contains only letters in javascript

With /^[a-zA-Z]/ you only check the first character:
  • ^: Assert postion at the beginning of the string
  • [a-zA-Z]: match a single character present in the list below:
    • a-z: A character in the range between "a" and "z"
    • A-Z: A character in the range between "A" and "Z"
If you want to check if all characters are letters, use this instead:
/^[a-zA-Z]+$/.test(str);
  • ^: Assert postion at the beginning of the string
  • [a-zA-Z]: match a single character present in the list below:
    • +: Between one and unlimited times, as many as possible, giving back as needed (greedy)
    • a-z: A character in the range between "a" and "z"
    • A-Z: A character in the range between "A" and "Z"
  • $: Assert postion at the end of the string (or before the line break at the end of the string, if any)
Or, using the case-insensitive flag i, you could simplify it to
/^[a-z]+$/i.test(str);
Or, since you only want to test, and not match, you could check for the opposite, and negate it:
!/[^a-z]/i.test(str);

Wednesday, July 6, 2016

Allow validation of hidden elements, override the ignore and set it to empty string

To allow validation of hidden elements, override the ignore and set it to empty string:
$("#form1").validate({
    ignore: "",
    rules: {
        something: {
            number:true,
            min:1,
            required:true
        }
    }
});
Check this out : http://stackoverflow.com/questions/7952181/jquery-validation-plugin-validating-hidden-inputs-and-not-visible


Sunday, June 19, 2016

Select2 4.0 placeholder undefined


Answer form stackoverflow

down voteaccepted
in this example if we delete || repo.text from formatRepoSelection it will not work. Because the repo.text is placeholder.
P.S. select2 4.0 do not need to empty option tag for placeholder working

Source : http://stackoverflow.com/questions/30302329/select2-4-0-placeholder-undefined

Friday, June 3, 2016

intl-tel-input-french-translation

intl-tel-input-french-translation

Check this out : https://jsfiddle.net/9yvdzv0a/2/

Friday, May 6, 2016

Caching a jquery ajax response in javascript/browser

Check this out : http://stackoverflow.com/questions/17104265/caching-a-jquery-ajax-response-in-javascript-browser

Monday, March 21, 2016

Supprimer les accents en Javascript

String.prototype.sansAccent = function(){
    var accent = [
        /[\300-\306]/g, /[\340-\346]/g, // A, a
        /[\310-\313]/g, /[\350-\353]/g, // E, e
        /[\314-\317]/g, /[\354-\357]/g, // I, i
        /[\322-\330]/g, /[\362-\370]/g, // O, o
        /[\331-\334]/g, /[\371-\374]/g, // U, u
        /[\321]/g, /[\361]/g, // N, n
        /[\307]/g, /[\347]/g, // C, c
    ];
    var noaccent = ['A','a','E','e','I','i','O','o','U','u','N','n','C','c'];
     
    var str = this;
    for(var i = 0; i < accent.length; i++){
        str = str.replace(accent[i], noaccent[i]);
    }
     
    return str;
}

http://www.finalclap.com/faq/257-javascript-supprimer-remplacer-accent

Monday, November 10, 2014

Way to get url, protocol in javascript

First get the current address
var url = window.location.href
Then just parse that string
var arr = url.split("/");
your url is:
var result = arr[0] + "//" + arr[2]