0

<form name="regForm">
<input type="text" id="username" name="username" ng-model="username" required>
 <button ng-click="submitSignup()" type="submit" ng-disabled=" (regForm.username.$dirty && regForm.username.$invalid) || regForm.username.$pristine">Sign Up</button>
 </form>

I want the input field to be invalid and the sign up button disabled whenever one presses white space. I don't want to allow white space in the input field either by typing or by pasting. The sign up button should be disabled whenever there is a white space either by typing or by pasting. Can someone help me out on this?

Taplar
  • 24,788
  • 4
  • 22
  • 35
atomty
  • 187
  • 2
  • 16
  • 1
    Sounds like you want angular logic that would make the input invalid if there is a space. This wouldn't require jQuery, so I've removed the tag. – Taplar Mar 28 '19 at 22:16

2 Answers2

1

the easy way to validate white spaces, is to trim the value of the input.

if(regForm.username.trim())

This conditional is true is the result is different to empty string.

Regards.

Deyvid Martinez
  • 430
  • 3
  • 8
0

you can also use ng-pattern to validate the input and disable the button on invalid pattern.

Follow that link

Ravi Mittal
  • 1,947
  • 4
  • 22
  • 37
  • I've followed that link, and I tried using `pattern="([A-z0-9À-ž])"` but I want it to accept other characters like underscore but not whitespace – atomty Mar 30 '19 at 22:40