javascript - Change Nan to String - Stack Overflow

admin2025-04-19  0

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
Add a ment  | 

3 Answers 3

Reset to default 2

You 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(); 
转载请注明原文地址:http://conceptsofalgorithm.com/Algorithm/1745073057a283402.html

最新回复(0)