I can check the validation of the number, How can I change to string in the same function?
hasValidPhone: function() {
var isValidPhone = /^\+?[\d-|,|]{7,15}$/.test(this.val());
return this.length > 0 ? isValidPhone : false;
},
I can check the validation of the number, How can I change to string in the same function?
hasValidPhone: function() {
var isValidPhone = /^\+?[\d-|,|]{7,15}$/.test(this.val());
return this.length > 0 ? isValidPhone : false;
},
Share
edited Feb 10, 2017 at 15:24
shma1001
asked Feb 10, 2017 at 13:43
shma1001shma1001
311 silver badge5 bronze badges
3
- typecast to string – M A SIDDIQUI Commented Feb 10, 2017 at 13:44
-
1
Do you mean the
toString()
function – roberto06 Commented Feb 10, 2017 at 13:45 - 1 Possible duplicate of What's the best way to convert a number to a string in JavaScript? – evolutionxbox Commented Feb 10, 2017 at 13:50
3 Answers
Reset to default 2You can do the following
var n = 14;
n.toString();
or
var n = String(14);
or
var n = 14+"";
var yourVar = String(this.val());
You can simply toSring function like this -
var num = 15;
var n = num.toString();