How to add validations in Forms?

Can somebody explain how to add a js validation to my field phone_number in my doctype Telefono step by step.I really want that all my phone number get this format

for example; (888)555-4444.
I actually did this js code → new RegExp(“(^[0-9]{3} [0-9]{3} [0-9]{4})$”);
May somebody help me to set the validation to my field phone numbe in my doctype Telefono ? please I really appreciate it.

let say we have a doctype name is number2word for example with two fields the first one is number and the one we want to show our result in is numbfo ,
we go to the doctype folder and open the number2word.js
and we put this code

frappe.ui.form.on("number2word", "number",
    function(frm) {
        var numb = parseInt(frm.doc.number);
        var ff = numb.format(0, 3, '-');

        frappe.model.set_value(frm.doctype, frm.docname, "numbfo", ff)
    });

    Number.prototype.format = function(n, x, s, c) {
    var re = '\\d(?=(\\d{' + (x || 3) + '})+' + (n > 0 ? '\\D' : '$') + ')',
     num = this.toFixed(Math.max(0, ~~n));

    return (c ? num.replace('.', c) : num).replace(new RegExp(re, 'g'), '$&' + (s || ','));
};

i used this format with my ff var ,
here is other format
12345678.9.format(2, 3, ‘.’, ‘,’); // “12.345.678,90”
123456.789.format(4, 4, ’ ', ‘:’); // “12 3456:7890”
12345678.9.format(0, 3, ‘-’); // “12-345-679”

or something like this
var myMoney=3543.75873;
var formattedMoney = ‘$’ + myMoney.formatMoney(2,‘,’,‘.’); // “$3,543.76”