This will work:
function validatePhoneNumberFormat(){
var phoneNumber = dijit.byId("phone");
var phoneFormat = /^\d{3}-\d{3}-\d{4}$/;
phoneNumber.validator = function(value){
console.log(value);
console.log(phoneFormat.test(value.trim()));
return phoneFormat.test(value.trim());
}
}
REGEX EXPLANATION
/^\d{3}-\d{3}-\d{4}$/
Assert position at the beginning of the string «^»
Match a single character that is a “digit” (ASCII 0–9 only) «\d{3}»
Exactly 3 times «{3}»
Match the character “-” literally «-»
Match a single character that is a “digit” (ASCII 0–9 only) «\d{3}»
Exactly 3 times «{3}»
Match the character “-” literally «-»
Match a single character that is a “digit” (ASCII 0–9 only) «\d{4}»
Exactly 4 times «{4}»
Assert position at the very end of the string «$»