See if Input Has Spaces with jQuery

后端 未结 2 948
陌清茗
陌清茗 2021-01-19 23:13

I\'m trying to write a function that reads a inputs value, and determines if a space has been used in it\'s creation. I\'m not trying to trim anything -- just see if it woul

2条回答
  •  栀梦
    栀梦 (楼主)
    2021-01-19 23:42

    Use contains for include space:

    var value = $('#myInputId').val();
    if(value.contains(' ')){
       console.log("has space");
    }
    

    Or you can find with these ascII code   and \xA0

    if(value.contains(' ')){
       console.log("has space");
    }
    

提交回复
热议问题