<![CDATA[
var $ = jQuery;
String locale = getUserLocale();
$(document).ready(function() {
if (!isEmptyNull(locale) && locale.equals("zh_CN")) {
$("input[id*='text12']").mask('9999年99月99日');
}
else {
$("input[id*='text12']").mask('99/99/9999');
}
});
]]>
<p:calendar id="text12" styleClass="calendar" maxlength="10" pattern="#
{pc_Test.dateDisplayFormat}"></p:calendar>
If the locale is equal to 'zh_CN',
the masking would be '9999年99月99日'
. Otherwise, it would would be '99/99/9999'
.
When I remove the if else command, it works. But if I put the if else command inside, it doesn't work.
How do I solve it?
This works quite well (tried it in console on the jquery mask page)
but if you want the mask format to show up in the input field you need to pass it as placeholder attribute
hope this helps
Here is a more complete masking that allows backspaces and if a zero is forgotten to be typed before any month less than 10 it will add one, as well as a little help for the month. You'll have to excuse my javascript, but hey it works right?
Try out this code, this will format your date in mm/dd/yyyy format as you type it in the input box. Create an onchange event on the input box and call the date_formator function with the input date.
I had some trouble getting the currently accepted answers to work properly while retaining the ability to backspace. This was my solution. It retains backspacing and also doesn't show the slash until the number following it is typed.
I've also create a github gist for this snippet here.
Check out the below code..
Hope this is what you are looking for!