Standage Standage - 1 year ago 90
jQuery Question

.mask with .toUpperCase() for Postcodes

I want to use the following .mask

$(document).ready(function() {
$('#postcode').mask('a9a 9a9');

});


But also on every Key stroke force the lower case to be uppercase but to also allow lowercase to be entered (I didn't just want to set the definition of the mask to be always uppercase), this is what i tried so far without success (it kinda works but doesn't keep the cursor position)

$("#postcode").keyup(function (e) {

var this2 = $('#postcode').val().toUpperCase();

$('#postcode').val(this2);

});

Answer Source

I found a workaround by adding this to the text box:

style="text-transform: uppercase" 
Recommended from our users: Dynamic Network Monitoring from WhatsUp Gold from IPSwitch. Free Download