by Planet Telex

- jQuery 1.6+
- Regex expression matches can be a constant length to account for URL shortening.
- Customizable "Characters left" label.
- Label can "pulse" on and off when the maximum characters has been exceeded.
- Use any CSS styling you wish.
Include jQuery and jQuery Textmeter:
<script type="text/javascript" src="js/jquery-1.11.2.min.js"></script>
<script type="text/javascript" src="js/jquery-textmeter.min.js"></script>
Have a textarea in your HTML:
<div id="content">
<p>
Begin typing into the box below to see jQuery Textmeter in action.
</p>
<textarea rows="10" cols="10"></textarea>
</div>
Add the JavaScript to textmeter your container:
<script type="text/javascript">
var pt = {};
pt.config = {
shortener: {
urlLength: 10
},
regex: {
"url": /\b(https?:\/\/?\w{2,}[^\s()<>]+(?:\([\w\d]+\)|([^[:punct:]\s]|\/?)))/
}
};
$(function () {
// This configuration accounts for all URLs being shortened to 20 characters.
$("textarea").textmeter(100, {
ignoreRegex: pt.config.regex.url,
ignoreRepacementSize: pt.config.shortener.urlLength
});
});
</script>
See the demo in action for a complete example.
- jQuery: MIT/GPL license
Copyright 2015 Planet Telex, Inc.
Licensed under the Apache License, Version 2.0 (the "License");
you may not use this file except in compliance with the License.
You may obtain a copy of the License at
http://www.apache.org/licenses/LICENSE-2.0
Unless required by applicable law or agreed to in writing, software
distributed under the License is distributed on an "AS IS" BASIS,
WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
See the License for the specific language governing permissions and
limitations under the License.