Question: I'm looking for a way using jquery/javascript to get a class name when I only know part of it and there are more than one classes applied to that element.

So if I'm looking for a class that I know starts with "charLimit\_" I want to know that full class name even when it's not the only class applied to a given element.
Example HTML would be.

```
<input class="charLimit_30 lastNameValidation" type="text" />

```

What I have so far below will put both "charLimit\_30" and "lastNameValidation" into an array, but how do I then say I only want "charLimit\_30" and then only tell me the value found after the underscore (30).

```
var classMName = $('[class*=charLimit_]').attr("class").split(' ');

```

Thanks in advance for you help!!!

Answer: 
This is kinda like what inkedmn said, but in a more jQuery-ish way:

```
var numbersAfterCharLimit = [];

$('[class*="charLimit_"]').each(function() {
    var matches;
    if (matches = this.className.match(/(?:\s+|^)charLimit_([0-9]+)(?:\s+|$)/)) {
        numbersAfterCharLimit.push(parseInt(matches[1], 10));
    }
});

```
If you only need first occurrence and everything that follows underscore in class is a number, then something like this would do it:

```
$('[class*=charLimit_]').attr("class").match(/(?:\s|^)charLimit_(\d+)/)[1];

```