Regular expression for not allowing spaces in the input field
Use +
plus sign (Match one or more of the previous items),
var regexp = /^\S+$/
While you have specified the start anchor and the first letter, you have not done anything for the rest of the string. You seem to want repetition of that character class until the end of the string:
var regexp = /^\S*$/; // a string consisting only of non-whitespaces