Mask Help

Any suggestions for creating masks? For example, formatting a phone number to display as (XXX) XXX-XXXX? Seems like a feature that a lot of people would make use of here, but I don’t find a lot of information about it.

Here’s the code that I have so far. “phone2” is the Field Code.

What I want is for us to be able to save telephone numbers as ten-digit strings that get masked to include the () - characters (so, we save the data as 5551234567, but it displays as (555) 123-4567).

(function() {
"use strict";'phone2')'', function () {
var last = $(this).val().substr( $(this).val().indexOf("-") + 1 );

if( last.length == 3 ) {
var move = $(this).val().substr( $(this).val().indexOf("-") - 1, 1 );
var lastfour = move + last;

var first = $(this).val().substr( 0, 9 );

$(this).val( first + '-' + lastfour );

Hello James,

After reviewing your code, I noticed that you might have an error at the following function.'phone2')

I don’t think you can add an event in the properties of the getFieldElements function.

Also, getFieldElements function with “s” at the end can be only available at the record list page. Therefore, you can use “” for “”(the record details page) instead.



At my Kintone app, I was able to format a string as a phone number using regular expressions as the code below.

(function() {
"use strict";[''], function (event) {

var wEle ='phone2');
var wRecord = event.record;

var wStr = wRecord.phone2.value;

wStr = wStr.replace(/(\d{3})(\d{3})(\d)/, "($1)$2-$3");

wEle.innerText = wStr;

return event;


The only concern I have at the above sample code is that if you use a link field with Telephone Number type setting for “phone2” field and want to leave the link feature as is, you might want to revise a value to set to “wEle.innerText” somehow. In the case, I do not think the API can be used, so you might want to check out how to do it.

▼ Link at Field Type Descriptions

Hope it helps.

Thank you.


That totally works! Wow! Thanks!

My JS is a bit rusty, please forgive me :slight_smile:

No real need for the Telephone Number type setting for this. COol feature, but not one we need at this point.

Appreciate all the help!