python ruby-programming-language Smalltalk Vue.js Knockoutjs TypeScript JavaScript, OOPs JavaScript Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 8,7,6,5,4 and 2 Interview Questions and Answers Angular 4 Angular 2 AngularJs 1.x NodeJs Perl Programming R Programming RequireJs Rust Programming Backbonejs closure programming language go-programming-language kotlin-programming-language
Generate an abbreviation form a string in JavaScript using regular expressions?

Abbreviation of a string in JavaScript using a Regular Expressions

Table of Contents
  1. HTML View for Description textarea
  2. JavaScript methods and call onkeyup 

For example, when we type ccc and press the space key that time [ccc => conference call with customer]. here the value of ccc is predefined the array list. 












<textarea id="txtDescription" onkeyup="return checkAbbreviationKey(event)"></textarea>


JavaScript methods and call onkeyup 

function checkAbbreviationKey(evt) {
    var charCode = (evt.which) ? evt.which : event.keyCode
        if (charCode == 32) {          
            var charStr = evt.target.value.match(/\S+/g)
            var abbreviations = isAbbreviations();               
            if (abbreviations.length > 0) {
               for(var index in abbreviations) {
                   var reg = new RegExp("\\b" + abbreviations[index].Anchor + "\\b", "g");
                   if (charStr[charStr.length - 1].match(reg)) {
                       charStr[charStr.length - 1] = abbreviations[index].ExpandedText;
                       evt.target.value = charStr.join(" ");
                   }
               }
            }
       }
}   

function isAbbreviations() {
    var abbreviationsList = ConstraintsList();        
    return abbreviationsList;
   }
}



ANIL SINGH

Hi there! Welcome to my blog. My name is Anil Singh. I'm a author of this blog. For more detail about me, kindly refer to this link..
My Blogs - http://code-sample.com and http://code-sample.xyz
My Books - Interview Questions and Answers Books- Get Your Book in 15+ Digital Stores Worldwide..

You Might Also Like
www.code-sample.com/. Powered by Blogger.
ASK Questions