email validation in jquery validate js resulting in ie 8 hanging - regex

The email validation given in jquery validate results in internet explorer 8 browser hanging when we add a long mail id like this
A#ABCDEFGHIJKLMNOPQRSTUVWXYZABCDEFGHIJKLMNOPQRSTUVWXyz
return this.optional(element) || /^[a-zA-Z0-9]+([_.-]?[a-zA-Z0-9]+)#[a-zA-Z0-9]+([.-]?[a-zA-Z0-9]+)(\.[a-zA-Z]{2,4})+$/i.test(value);
what could be the possible changes made to avoid this

<input type = "email" name="email" />
This would work

Related

cfinput not accepting .education domain names

For the first time ever I had two users come into my app with a .education top level domain. Their email address looked like this: user#domain.education. I'm using the cfinput validate attribute on the form they are filling out as follows:
<cfinput type="text" name="email" required="yes" message="Please enter a valid email address." validate="email">
When the users submits the form they are getting my error message. The form has been working successfully for years on all the other email addresses entered. Are there any tricks to make it take this top level domain? TIA
Avoid all of the ColdFusion UI tags. They will only cause pain.
Each version of ColdFusion updates the built-in email validation to handle the new top-level domains (TLD) of the time. There are nearly 1600 active TLDs at the moment.
Javascript validation isn't going to cut it.
Regular expressions won't either.
You will need to validate on the server if you aren't already.
Better you remove that validation rule for a start and send an email to verify the email account exists before activating the user on your app.
I agree with the other answers about limiting your use of cfinput, but as a quick fix you should be able to use the cfinput PATTERN attribute (https://helpx.adobe.com/coldfusion/cfml-reference/coldfusion-tags/tags-i/cfinput.html):
<cfinput type="text" name="email" required="yes" message="Please enter a valid email address." validate="regex" pattern="(?:[a-z0-9!##$%&'+/=?^_{|}~-]+(?:\.[a-z0-9!##$%&'*+/=?^_{|}~-]+)|"(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21\x23-\x5b\x5d-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])")#(?:(?:a-z0-9?.)+a-z0-9?|[(?:(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?).){3}(?:25[0-5]|2[0-4][0-9]|[01]?[0-9][0-9]?|[a-z0-9-][a-z0-9]:(?:[\x01-\x08\x0b\x0c\x0e-\x1f\x21-\x5a\x53-\x7f]|\[\x01-\x09\x0b\x0c\x0e-\x7f])+)])">
The PATTERN attribute can be changed to any regular expression. The one provided is RFC 5322 compliant.
EDIT: Changed pattern to Java based RegEx and escaped #'s

Form Validation On Frontend or Backend Django

I have an HTML form with a date field:
<input type="date" class="form-control" placeholder="Date" name="date" autocomplete="off" required>
Before submitted the form, I want to ensure that the date that was entered is greater than the current date. If it is older, then I want to show a custom form validation to say something like, "You must enter a date past today.".
Do you suggest I do this validation on the backend or the frontend? Thanks!!
I think you're better off doing in within django forms. The reason is, if you do it in the front-end, you'll have to repeat the code when applying this property elsewhere.

Asp.net core passing multiple parameter + web api

I am submitting a form that passes three values to the controller, which are email, fullname and id fields.
#using (Html.BeginForm("SubmitResult", "TestAPI", FormMethod.Post, new { id = "postEmailForm" }))
{
<div id="details-container">
<input type="text" name="email" />
<input type="text" name="fullName" />
<input type="text" name="studentId" />
<button type="submit" id="send">Send</button>
</div>
}
Controller:
[HttpPost("SubmitResult/{email}/{fullName}/{studentId}")]
[Authorize(Roles = "Admin, Shop")]
public IActionResult SubmitResult(string email, string fullName, long? studentId)
{
}
However, when I click on submit button, it throws an error message in the console.
OPTIONS https://localhost:50138/TestAPI/SubmitResult
net::ERR_SSL_PROTOCOL_ERROR.
Headers:
Request URL: https://localhost:50138/TestAPI/SubmitResult
Referrer Policy: no-referrer-when-downgrade
How do I properly decorate the attribute in the controller, so I can pass multiple parameters to test API using Postman?
I was expecting something like below to work for testing.
http://localhost:50138/api/TestAPI/SubmitResult/test#gmail.com/MikeShawn/2
There are few issues with your code.
First issue is that it looks like when you post the data it tries to send it using a cross-origin request. If this is on purpose then you have to add CORS middleware in your pipe. If not - you have to figure out why it happens and fix it. There are not enough details in your question to say why it happens.
Two URLs have the same origin if they have identical schemes, hosts, and ports.
Second issue is that you are trying to send data by adding parameters to URL. This is wrong because the data will be sent in the request body. So regarding HttpPost attribute it should look like this:
[HttpPost]
[Authorize(Roles = "Admin, Shop")]
public IActionResult SubmitResult(string email, string fullName, long? studentId)
{
}
UPDATE
Just looked at your question again. It seems the page with form itself was opened using http scheme, but the POST request is actually going to https scheme. So to resolve first issue make sure that page with form is loaded using https scheme too.

How do I pass multiple variables from one handler to another in GAE?

I want to redirect users to a confirmation page that will display both subject and content (if there is any) if they enter a valid subject, but stay on the same page and display an error if the subject is either blank or over three hundred characters.
Here is my backend code:
def post(self):
subject = self.request.get('subject')
content = self.request.get('content')
a, b = self.validSubject(subject)
if a == True and b == True:
self.redirect('/confirm')
else:
if a == False:
error = "Title cannot be blank!"
if b == False:
error = "Title cannot be over 300 characters."
self.render("newpost.html", subject = subject, content = content, error = error)
Here is the code for the newpost.html template:
<h2>New Question</h2>
<hr>
<form method="post">
<label>
<div>Title</div>
<input type="text" id="subject" name="subject">
</label>
<label>
<div>
<textarea name="content" id="postcontent"></textarea>
</div>
</label>
<b><div class="error">{{error}}</div></b>
<input type="submit">
</form>
I've tried adding action="/confirm" to the POST form, but that redirects to /confirm even if there is an error. I've looked at the webapp2 documentation but couldn't find anything on how to pass variables on a redirect. (https://webapp-improved.appspot.com/api/webapp2.html#webapp2.redirect)
I'm using webapp2 and jinja2. Thanks for any help in advance, I've been looking at this piece of code for quite a while :(
The pattern you're trying to write doesn't work within http, irrespective of what backend platform or language you're using. Your HTML is posting to the server and the GAE code is handling the post. At that point in the interaction, the browser has already submitted and is awaiting a response from the server. You can't stop the submission at that point since it's already happened.
You should consider validating the input in Javascript before the form is even submitted to the server. That way you can suppress the submission of the form in the first place if your data isn't valid.
Take a look at the following question to see an example of this:
JavaScript code to stop form submission

change default form email type regex in symfony2

Using Symfony 2.3.4.
When I create a form with a field in it that's supposed to process emails I go and use the default email type:
builder->add('email', 'email', array(
'label' => 'Email',))
with only this, it successfully validates user inputs, only not the way I want, meaning:
how it works:
me --> notallowed
me#gmail --> allowed
how I need it to work:
me --> notallowed
me#gmail --> notallowed
me#gmail.com --> allowed
summing up:
I figured what I need is to change/customize the default regex that validates this which I guess is deep in one of the many files in symfony.
appreciate any tips regarding this, thanks
Actually, the validation that you are seeing here is the browser based HTML5 validation. The message that pops up if me is entered comes right from your browser, no Symfony involved. I find HTML5 validation unreliable for the most part. Best practice is to validate on the server side, and use some type of javascript validation for the client side.
for more info on setting up server side validation, see the symfony docs, they give some great examples and it is very useful.
You can handle email validation by javascript . Call any method on form submit like
function validate(){
var email=$('#email').val();
if(email!=""){
var re =/^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4})+$/;
if (!re.test(email)) {
alert('please Enter Valid email address');
}
}
<form onSubmit="return validate();">
<input type="text" name="email" id="email" placeholder="Please Enter your Email address" />
</form>
Please refer this following link for form field type email
Symfony form type email
If you want jquery validation for email
$('#formId').validate({
errorClass: 'help-block',
rules: {
'textFieldName': {
required: true,
email: true
}
},
messages: {
'textFieldName': {
email: "Invalid Email Address"
}
},
highlight: function (element) {
$(element).parent().parent().removeClass("success").addClass("error");
},
unhighlight: function (element) {
$(element).parent().parent().removeClass("error").addClass("success");
}
}); // validate