Question about Regex to edit claim and remove part of email / username - regex

Completely new to regex only read a few guides my problem is as follows. A 3rd party solution is being connected to our Adfs 2016 enviroment. We have run into a problem as the solution cannot handle long usernames and the Upn and email of our users are in the format of users initials 3 or 4 letters.department#ourcompany.com, so Dave Dibley Jr would be ddj.department#ourcompany.com
what i would like to do is use Regex to Cut everything after the initals from the claim any suggestions how to do this ?

You can use RegEx for string manipulation in the Claims Rules Language. Fx:
c:[type == “http://contoso.com/role”]
=> issue (Type = “http://contoso.com/role”, Value = RegExReplace(c.Value, “(?i)director”, “Manager“);
Pass through any role claims. If any of the claims contain the word “Director”, RegExReplace() will change it to “Manager”. For example, “Director of Finance” would pass through as “Manager of Finance”.
See https://social.technet.microsoft.com/wiki/contents/articles/16161.ad-fs-2-0-using-regex-in-the-claims-rule-language.aspx for more information.

Related

Default regex django uses to validate email

recently, I started playing with Django and created a custom form for user registration. In that form to create the field for email I use something like
email = forms.EmailField()
I observed that address such as a#a.a is considered invalid by the form. Of course this is a nonsense email address. Nonetheless, I wonder how does Django checks for validity.
I found some topics on the net discussing how to check for validity of an email address but all of them were providing some custom ways. Couldn't find something talking about the django default validator.
In their docs on the email filed they specify
Uses EmailValidator to validate that the given value is a valid email address, using a moderately complex regular expression.
However that's not very specific so I decided to ask here.
For anyone also interested in this, I would suggest looking up the implementation (django.core.validators) as was kindly suggested by iklinac in the comments.
In it, there is not just the source but also mentions about standards that were used to derive regexes that check if domain and literal have valid format.
us should check docs here https://www.geeksforgeeks.org/emailfield-django-forms/#:~:text=EmailField%20in%20Django%20Forms%20is,max_length%20and%20min_length%20are%20provided.
if u wanna check validation use clean function like this :
from django.forms.fields import EmailField
email = EmailField()
my_email = "a#a.a"
print(email.clean(my_email))
if your email is valid then this func return value else return validation error

Regex - Coverting URLs to clickable links

We have some regex code that converts URLs to clickable links, it is working but we are running into issues where if a user submits a entry where they forget to space after a period it thinks it's a link as well.
example: End of a sentence.This is a new sentence
It would create a hyperlink for sentence.This
Is there anyway to valid the following code against say a proper domain like .com, .ca ect..?
Here is the code:
$url = '#(http)?(s)?(://)?(([a-zA-Z])([-\w]+\.)+([^\s\.]+[^\s]*)+[^,.\s])#';
$output = preg_replace($url, '$0', trim($val[0]));
Thanks,
Aaron

How do I filter email in cpanel using 'match regex' for the following?

I'm looking to filter the following emails in cpanel via regex.
Buy New Furniture <spamword234#ryrtyhd.net>
Win Jackpot <spamword5346#dfsdfs.com>
<spamword678#fdgsaj.com>
So basically i want to filter an email if it matches the following in the email header.
From: any name here, present or absent <spamword(any numbers from 0-9999)#anydomain.extension
Any ideas? Help appreciated!
.*\<spamword[0-9]{1,6}\#.+\>$

how to obtain a regular expression for validation email address for one domain ONLY?

I am struggling with writing a regex for validating email address for only one domain.
I have this expression
[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}
But the issue is that for example hello#gmail.com.net is valid and I only want to be only valid for only one domain. So hence I do not want hello#gmail.com.net to be valid.
Help is needed. Thank you!
try this [A-Z0-9a-z._%+-]+#[A-Za-z0-9-]+\.[A-Za-z]{2,64}.
In your regex is a dot in the allowed characters behind the #.
You can use something like:
\b[A-Z0-9a-z._%+-]+#gmail\.com\.net\b
Regex Demo
I found this regex for Swift:
[A-Z0-9a-z._%+-]+#[A-Za-z0-9.-]+\\.[A-Za-z]{2,64}
It has an extra backslash.
I found it here: http://emailregex.com/
Regards,
Melle
I know you already accept an answer but this idea just cross my mind. You can use URLComponents to split the email address into user and host and validate each component separately:
func validate(emailAddress: String) -> Bool {
guard let components = URLComponents(string: "mailto://" + emailAddress),
let host = components.host else
{
return false
}
return host.components(separatedBy: ".").count == 2
}
print(validate(emailAddress: "hello#gmail.com")) // true
print(validate(emailAddress: "hello#gmail.com.net")) // false
print(validate(emailAddress: "hello")) // false
Your requirement has a big flaw in it though: valid domains can have two dots, like someone#bbc.co.uk. Getting a regex pattern to validate an email is hard. Gmail, for example, will direct all emails sent to jsmith+abc#gmail.com to the same inbox as jsmith#gmail.com. The best way is to perform some rudimentary check on the email address, then email the user and ask them to click a link to confirm the email.
You can try with below pattern.
/^(([^<>()\[\]\.,;:\s#\"]+(\.[^<>()\[\]\.,;:\s#\"]+)*)|(\".+\"))#((REPLACE_THIS_WITH_EMAIL_DOMAIN+\.)+[^<>()[\]\.,;:\s#\"]{2,})$/i;
for Eg.
/^(([^<>()\[\]\.,;:\s#\"]+(\.[^<>()\[\]\.,;:\s#\"]+)*)|(\".+\"))#((gmail+\.)+[^<>()[\]\.,;:\s#\"]{2,})$/i;

Laravel 4 regex email validation

I am trying to add validation, inside my User model to validation emails using regex.
However, it's spits a dummy out at the first apostrophe.
'email' => 'required|regex:/^[a-zA-Z0-9.!#$%&'*+\/=?^_`{|}~-]+#[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?(?:\.[a-zA-Z0-9](?:[a-zA-Z0-9-]{0,61}[a-zA-Z0-9])?)*$/',
Have you tried the 'email' validation rule?
'email' => 'required|email|unique:users,email'
http://laravel.com/docs/4.2/validation#rule-email
As the answer to this question on SO states, there is no simple regular expression to validate an email-address. Using your RegEx could maybe catch valid addresses (although that's just speculation of mine). Using the email-validation-rule would be my first choice.
But you are right, this is just the server side in the first place, if you ignore redirecting users back with input and error messages..
On the client-side, you would have some options. The first one would be to simply rely on the build in browser-validation, by declaring the corresponding input-field as an email-address which you should do anyway:
{{ Form::email($name, $value = null, $attributes = array()) }}
Another, more advanced way would be to create some kind of helper to check the typed input via Ajax using the same validation rule and returning the error messages or sth. similar. This could be an additional route to your Model-Resource for example. This way, you would be stable and consistent.