How would you in angular validate for that a text box has no spaces. Is there a built in expression or would I have to fall back on a regular expression?
For example I would like if a user types in the following into a text input field
Pass/valid:adf
Fail/Dirty:a s d
Yes, you would need a pattern. Required is just going to make sure something is in there. I'm sure you've looked at it but for others, Angular docs show the available input validation options:
http://docs.angularjs.org/api/ng/directive/input
what about this:
ng-pattern="/^\s*\w*\s*$/"
this regex evaluates for spaces inside the input
Related
I am trying to write an expression for AngularJs. I need to use it inside an ng-pattern directive so to put a validation constraint to a form.
What I actually need is a regex for a URL in https that has always to end with a slash: /.
It would be nice if it ends more specifically in /pre/last/
How do I solve this problem?
This RegEx might help us to match /pre/last/. It creates two groups, in case we wish to call those groups, we can do so using $2 for /pre/last/ and $1 for first the part of our URL (Please see the image).
'/(.+)(\/pre\/last\/)/g'
We might not want to bound it with start (^) or end ($) anchors, and it might still does our desired matchings.
This post explains how we would do so in JavaScript.
Maybe this help
/.*\/pre\/last\/$/g
what it basically match is any string that ends with /pre/last/
I want to validate an email for only certain type of kind. So I know that I need to use ng-pattern expression to make custom validation. I went through the Angular docs but I could not understand how to use it.
The solution I am looking for is something like, for instance, I want users to only use "anychar mix with num #gmail.com" for email when registering.
A try that I have thought of but i know this is not good. I have fixed after the #gmail.com which will match but how to do before of the mix of chars or numbers?
My test sample:
var pattern = '[a-z][0-9]+\#+gmail+\.+com';
<input ng-pattern="pattern"/>
Can you kindly guide me on this one?
Thank you !
This is the best pattern to check valid email address:
ng-pattern='/^(([^<>()\[\]\\.,;:\s#"]+(\.[^<>()\[\]\\.,;:\s#"]+)*)|(".+"))#((\[[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}\.[0-9]{1,3}])|(([a-zA-Z\-0-9]+\.)+[a-zA-Z]{2,}))$/'
You can try this another regex:
ng-pattern='/^(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){255,})(?!(?:(?:\\x22?\\x5C[\\x00-\\x7E]\\x22?)|(?:\\x22?[^\\x5C\\x22]\\x22?)){65,}#)(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22))(?:\\.(?:(?:[\\x21\\x23-\\x27\\x2A\\x2B\\x2D\\x2F-\\x39\\x3D\\x3F\\x5E-\\x7E]+)|(?:\\x22(?:[\\x01-\\x08\\x0B\\x0C\\x0E-\\x1F\\x21\\x23-\\x5B\\x5D-\\x7F]|(?:\\x5C[\\x00-\\x7F]))*\\x22)))*#(?:(?:(?!.*[^.]{64,})(?:(?:(?:xn--)?[a-z0-9]+(?:-+[a-z0-9]+)*\\.){1,126}){1,}(?:(?:[a-z][a-z0-9]*)|(?:(?:xn--)[a-z0-9]+))(?:-+[a-z0-9]+)*)|(?:\\[(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){7})|(?:(?!(?:.*[a-f0-9][:\\]]){7,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,5})?)))|(?:(?:IPv6:(?:(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){5}:)|(?:(?!(?:.*[a-f0-9]:){5,})(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3})?::(?:[a-f0-9]{1,4}(?::[a-f0-9]{1,4}){0,3}:)?)))?(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))(?:\\.(?:(?:25[0-5])|(?:2[0-4][0-9])|(?:1[0-9]{2})|(?:[1-9]?[0-9]))){3}))\\]))$/';
I have a HTML form with a bunch of inputs named geometrie_1_bezeichnung, geometrie_1_stack, geometrie_2_bezeichnung, geometrie_2_stack and so forth.
ng-model of these fields is created dynamically like product.geometrie_2_bezeichnung.
$scope.submitSave = function(product){ console.debug(product) }
Angular splits these values and creates arrays like geometrie[][bezeichnung] and adds these to my productobject.
My CMS in the background doesn't like this. I want/need only the raw values. Is there any way to stop Angular from doing this? (This might be Angular 1.4 behaviour, not sure though)
Thanks,
thomas
Would be good to see your Code.
But to be sure... geometrie_1_bezeichnung is made to geometrie[][bezeichnung]?
Did you try to remove the underscores from the input names?
I have implemented Angular Js search functionality in application. When I have enter more than one special characters for example '!#' it will display all the results.I think the exclamation character is the problem. How can I resolve this? In their demo site is also not working.http://docs.angularjs.org/api/ng.filter:filter
source can find from their site.
See you are working somewhat wrong, because it allows you to have the multiple special characters search, but in your case you are using "!#" it means not include all those result having "#" in it.
So, if you choose to have "#*" it will show you to get all the result having these characters together.
I would like to use angular's number validation, however it looks like it requires input type=number? usually this would be fine, except I don't want the up and down arrows that appear to the right of this type of input by default.
Is there an alternative solution? I tried using ng input number with input text but it didn't work for me :/
Use <input type="number" />
And read this article: Can I hide the HTML5 number input’s spin box?