Parsley.js Validation Requirement - parsley.js

Good afternoon all! I am looking for some guidance to see if this type of validation is possible. I work for a college and am using a form that pushes to our CRM when complete. I am looking for parsley to only validate the email address field IF they enter their college email address. Is this possible? I am trying to weave out personal email accounts and keep everything uniform with the same email address.
Thanks in advance!

You can do that e.g. by using data-parsley-pattern and defining a pattern that matches only the required mail addresses. The pattern to validate against the mail addresses you mentioned in your comment might look like this:
.*#(mail\.)?walshcollege.edu$
This matches everything that:
Starts with any number (*) of arbitrary characters (.)
Followed by an #
Might be followed by "mail.". The dot is escaped to avoid the special meaning "any character", the question mark means "might be there or not" and the parentheses make the question apply to the complete string.
Ends with walscollege.edu (the $ means the end of the string)
If you also want to make sure that an mail address is inserted you need to add data-parsley-required as Parsley by default does not validate empty fields.
Also keep in mind that Parsley validation is only client side, so you should add validations in the server to really make sure that no wrong mail address is used.

Related

Twilio sample react app trying to pass a room name in the URL and put it into a hidden field?

I know this sounds like a big ask, but I'm assuming someone else has already done this and has a simple answer because it seems like an obvious use case.
Twilio has a sample app available on GitHub for their video service. Unfortunately, I don't know much about react, so I was able to make a couple of little changes, but this one has me stumped.
The code is called: Twilio / twilio-video-app-react
https://github.com/twilio/twilio-video-app-react
When you launch the code to enter a video room, you are presented with a form to enter your name and the name of a video room. I need to remove that room name input field and replace it with a hidden variable that was provided in the URL. In other words:
Get a room name variable that was passed as a query parameter on the URL
Make sure the room name is "safe" (alphanumeric) and then put it into a hidden variable in the form
Remove the visible input field (room name) from the form
That would take me two minutes in PHP, and it's probably really easy in react as well, but I can't figure it out. Hope someone can point me in the right direction.

How to make a password include at least one special character?

The password field should be more than 8 characters and include at least one special characters. How to meet the 'at least one special character' requirement in AngularJS?
<input type="password" name="pwd" data-ng-minlength="8" data-ng-model="user.pwd" />
How to add password validation using regular expression in angularjs according to certain criterion?
This question is very helpful to me, but my password requirement is slightly difference, like no number is allowed in my password, and I want to seperate the length requirement and special character requirement if possible so I can tell users what is the exact error. And I just wonder where can I learn how to set up ng-pattern? For me, they look like random characters...like this one:
ng-pattern="/^(?=.*[A-Za-z])(?=.*\d)(?=.*[$#$!%*#?&])[A-Za-z\d$#$!%*#?&]{8,}$/"
You can do this easily with below code
var regularExpression = /^(?=.*[0-9])(?=.*[!##$%^&*])[a-zA-Z0-9!##$%^&*]{6,16}$/;
With the above regex you can complete your task, for detail study of it go to the link :
https://www.w3schools.com/Jsref/jsref_obj_regexp.asp

mail clients stripping part of angular url

I am sending a signup activation email containing a signup confirmation url with a confirmation token that points to an angular front end app:
...
Activate
...
Note that the token is a JWT and is fairly long.
This works find for most users, but for some clicking on the link takes them to https://domain/com only without the confirm-signup?token=...
It seems as though the mail client may be stripping off everything after the #, but I can't find any evidence of others having this problem, nor can I reproduce it.
My best guess so far is that some mail clients are seeing the # and somehow treating the trailing part as an internal anchor and stripping it...?
Has anyone else encountered this sort of problem? If so, have you found any solution short of replacing the whole mechanism with something else?
Some clients treat the hash-link just fine. Others don't. There's a conversation about Outlook being dirty about this here: Outlook strips URL hash from email
What we did to resolve this at our company is simply create a handler on our server that redirects. Your email link would become http://domain.com/email-link?url=https%3A%2F%2Fdomain.com%2F%23%2Fconfirm-signup%3Ftoken%3D1234 and your server side script would grab the query param url and immediately trigger a redirect.
You'd need to make sure that you find all links in your emails and replace them. Here's a PHP function for that, but you could do this in whatever backend language you're using. Regex here may be helpful at least.
function replaceLinks($html,$hash) {
return preg_replace_callback('/<a [^>]*href=[\"\']{1}(.+?)[\"\\\']{1}/', function($matches) use ($hash) {
return str_replace($matches[1],"http://domain.com/email-link?url=".rawurlencode($matches[1]),$matches[0]);
}, $html);
}
Yes I have encountered this issue before because of the #, I was trying to link to a anchor on a landingpage.. My solution ended up using a short.url service to "hide" the # from the html e.g. https://goo.gl/
Looks like you need percent encoding!
A lot of times when your href gets parsed (by angular in this case) it doesn't handle the special characters right, or strips them. Find your problem characters and replace them with %3F for ?, %26 for &, and %23 for #. The rest are in a chart in the link.
Once the encoded address hits the browser the url will be decoded in your url bar.

AngularJS Email Validation Fails

You can test from the original address: https://docs.angularjs.org/api/ng/input/input%5Bemail%5D
It fails when you remove the dot. How can I add that to requirements?
The perceived problem lies in the fact that an email without a dot is perfectly legal. bob#localhost is a valid email address. Until the RFC spec changes to require the dot, your choices are to apply extra validation client side via regex or handle this server side. See this post for a much lengthier explanation.
Using a regular expression to validate an email address

CakePHP IBM Tutorial: Incorrect API doc for Model::validate()?

Okay, this is driving me nuts. I’m working through the IBM CakePHP Tutorial, and in the first part, I’m at the section where the author is introducing validation rules for form input:
www.ibm.com/developerworks/opensource/tutorials/os-php-cake1/section5.html#N107E3
For the life of me, I can’t figure out what’s happening in this line of code:
$this->invalidate('username_unique');
According to the CakePHP documentation, the Model::invalidate() method takes as its first parameter a string that specifiies “The name of the field to invalidate”. How is “username_unique” the name of the field to validate? Looks to me like it should be just plain old “username”. But incredibly enough, the author’s code works, and mine doesn’t when I change “username_unique” to “username” (or even “User.username”), so I’m thinking there might be a serious flaw in the documentation (or very possibly, with me).
[FWIW, I can see that the CakePHP 1.25 provides a better means of doing validation, but I still find it troubling that what seems to be a well-documented method doesn't seem to be doing what it advertises, and I want to understand why the tutorial code works.]
Can anyone shed any light on this?
The "magic" is actually in the $form in this case.
When calling $this->invalidate('username_unique'), Cake takes a note that the field username_unique is invalid. The fact that this field does not actually exist is irrelevant.
Now, take another look at the actual $form field (slightly reformatted):
echo $form->input('username', array(
'after' => $form->error('username_unique', 'The username is taken. Please try again.')
));
It's outputting a normal form field, but "manually" places an error() output after the form field. $form->error('username_unique', $message) means "if there's an error for the field username_unique, output the message $message". So you're actually marking an imaginary field as invalid and are manually outputting an error message for this imaginary field.
And actually, that's a load of outdated cr*p you should forget right away. There's a built-in syntax for multiple validation rules per field, so you can test for character length and uniqueness at the same time and even get different error messages for each error type. There's even a built-in isUnique rule, so you won't even have to code a manual uniqueness test.

Resources