Your pattern must be RegEx literal (double quotes around that should not be there) like this
var pattern = /^(()?\d{3}())?(-|\s)?\d{3}(-|\s)?\d{4}$/;
Otherwise you need to use RegExp object, with proper escaping for \, like this
var pattern = new RegExp("^(()?\\d{3}())?(-|\\s)?\\d{3}(-|\\s)?\\d{4}$");