Any idea how to validate a phone number in javascript without using RegEx?
The phone number should be in this format:
xxx xxxxxxx
x -> number
Any idea how to validate a phone number in javascript without using RegEx?
The phone number should be in this format:
xxx xxxxxxx
x -> number
Well, there are a few ways I'm sure you could go about doing this.
First thing that comes to mind would be to put the string into an array of fixed length and then iterate through the array. if the array at position [3] is anything but a space, you know it's not a valid formatted number. also, if the re are too few or too many items for the array, then you know its invalid. and lastly, when you iterate through each item of the array, and it's not a number (or a space at the 4th position [3], then you know it's not valid.