javascript - I am taking user input and splitting it - how to best check types for each and also remove spaces? -


i'm not sure if there's better way this.

basically, taking user inputs example - hair salon, 1, 4

when split , ['hair salon',' 1',' 4']. doing error check make sure 3 values passed max, how can remove spaces (' 4') , check 'hair salon' string, , other 2 numbers?

thanks

suppose have user input

hair salon, 1, 4 

now split(','), array

var arr = ['hair salon', '1','4']

you every input string

for(i=0;i<arr.length;i++) {  arr[i] = arr[i].trim() // remove space & front } 

in case needed data type of inputs, can check using

typeof (arr[i])) - in loop 

hope, suffice need


Comments

Popular posts from this blog

ios - RestKit 0.20 — CoreData: error: Failed to call designated initializer on NSManagedObject class (again) -

laravel - PDOException in Connector.php line 55: SQLSTATE[HY000] [1045] Access denied for user 'root'@'localhost' (using password: YES) -

java - Digest auth with Spring Security using javaconfig -