Skip to content Skip to sidebar Skip to footer

JavaScript Regex To Validate An Input Is More Than 0 Characters

Forgive me if this is super simple, but I googled and googled and couldn't find a good example. I'm not that great with regex and just need to valid that an input has more than 1 c

Solution 1:

You can just use required for that:

<input type="text" ng-model="username" name="username" required>

See this pluckr fork: http://plnkr.co/edit/VwY1WPdCocKHwww69ZSj?p=preview

More in the docs: http://docs.angularjs.org/api/ng.directive:input#usage_parameters

If you REALLY want to use ng-pattern you should add start/end of input (^ and $):

<input type="text" ng-model="username" ng-pattern="/^$/">

But remember, this will validate a blank input (the input value matches the pattern).


Solution 2:

Use /.+/ (. means every possible character (except from new line characters and + means at least once)


Post a Comment for "JavaScript Regex To Validate An Input Is More Than 0 Characters"