0

please give me the code for checking the company name entered in textbox using javascript .Only sentence case to be allowed.Only abbreviations (without a full name) should not be allowed.(eg DPS) Abbreviations if any should be allowed only at the end of the name within ().eg Delhi Public School(DPS)

2
Contributors
5
Replies
6
Views
6 Years
Discussion Span
Last Post by Taywin
0

And how would you distinguish that "Dps" is not a company name? Or it is?

Edited by Taywin: n/a

0

It is a company name..only thing is user cannot simply enter abbrevation

0

OK, you can try to use regular expression to check whether the input string is valid. Below is my attempt to check the string using regex...

// javascript
function isCompanyName(str) {
  str = str.replace(/^\s+|\s+$/g, "")  // remove leading/tailing white spaces
  if (str.match(/^([a-z_]|\W|[A-Z][A-Z]+)/) ||  // start with lower case, non word char, or 2 capital letters
      str.match(/\s+[a-z]\w*/) ||  // a word contains all lower cases
      str.match(/\s+[A-Z][A-Z]+/)) {    // a word contains at least 2 capital letters
    alert("'"+str+"' is not a company name!")
  }
}

// HTML element
<input name="whatever" id="whatever" onchange="isCompanyName(this.value)">

Edited by Taywin: n/a

This topic has been dead for over six months. Start a new discussion instead.
Have something to contribute to this discussion? Please be thoughtful, detailed and courteous, and be sure to adhere to our posting rules.