. , , Unicode . , SQL Server NVARCHAR MySQL UTF-8 . , " ", ".
, , , , " ", , .
You really cannot generally expect anyone to hammer in UTF-8 byte numbers. Perhaps on the client side you can do this purely visually using the "amount of string used instead of a few bytes:
<style type="text/css">
.field { width: 12em; }
.field input { width: 100%; }
.field input { box-sizing: border-box; -moz-box-sizing: border-box; -ms-box-sizing: border-box; -webkit-box-sizing: border-box; -khtml-box-sizing: border-box; }
.indicator { background: blue; height: 5px; }
.indicator-over { background: red; height: 5px; }
</style>
<div class="field">
<input type="text" name="pwd" class="limited-12">
</div>
<script type="text/javascript">
function limitInput(element, limit) {
var indicator= document.createElement('div');
element.parentNode.insertBefore(indicator, element.nextSibling);
element.onchange=element.onkeyup= function() {
var utf8= unescape(encodeURIComponent(element.value));
indicator.className= utf8.length>limit? 'indicator-over' : 'indicator';
var used= Math.min(utf8.length/limit, 1);
indicator.style.width= Math.floor(used*100)+'%';
}
element.onchange();
}
var inputs= document.getElementsByTagName('input');
for (var i= inputs.length; i-->0;)
if (inputs[i].className.substring(0, 8)=='limited-')
limitInput(inputs[i], parseInt(inputs[i].className.substring(8)));
</script>
source
share