Generate Email Addresses with Special Characters [duplicate] - c#

This question already has answers here:
How do I remove diacritics (accents) from a string in .NET?
(22 answers)
Closed 3 years ago.
I am tasked with generating an email address for new users in our environment who may have special characters (such as an umlaut and accents) in their full names. While some email systems can handle these characters I am being told to generate email addresses that can convert these characters to a standard ASCII format.
So for example, John Señior would be created as john.senior#... and Jane Fraü would be created as jane.frau#...
Has anyone found a regex expression or library that can handle such a requirement.
UPDATE - I am planning on performing the replacement in PowerShell, but could use any Windows compiled libraries as well.

Having a better understanding of what I was trying to do, aka removing diacritics, I was directed to this article How do I remove diacritics (accents) from a string in .NET? which provided a good solution that I converted into use for PowerShell:
$name = "Jane Fraü"
$tempBytes = [System.Text.Encoding]::GetEncoding("ISO-8859-8").GetBytes($name)
$newName = [System.Text.Encoding]::UTF8.GetString($tempBytes)
Write-Host $newName
Jane Frau

Related

What is #property_name declaration means in C#? [duplicate]

This question already has answers here:
What's the use/meaning of the # character in variable names in C#?
(9 answers)
Closed 1 year ago.
I was browsing sources for microsoft .netcore runtime and came across these lines of code
as you can see they are using # symbol infront of every error message getter like #Error_InvalidFilePath.
My question is, what is this language feature that is being used here?
And, Where can I read more about it?
Thanks
The # is a way to use reserved words as names. E.g. the variable class could be used as variable name like #class.
For non reserved names this won't add anything. But of course you don't know which names are reserved in the future. Your code example is generated code, which should preferably work for newer language versions and so the # makes sense there.
See docs

Simple regex for email validation using C#. Has # symbol in the middle [duplicate]

This question already has answers here:
What's wrong with this RegEx for validating emails?
(5 answers)
Closed 2 years ago.
I don't know anything about regex.
How do I create an email validation that allows such entries?
Allow
a1b2c3#a1b2c3
a#a
1#1
a1#a#a2e
!s#s$ds
Dont Allow
#
###
!##
Basically allow characters that has # in the middle
If you aren't fluent in regex you can split the string at "#" and expect two elements.
If you want to use regex, the first result on google was: https://emailregex.com

Detecting and replacing all smilies in a string [duplicate]

This question already has answers here:
Mysql server does not support 4-byte encoded utf8 characters
(8 answers)
Closed 7 years ago.
I have a integration with facebook and have notice that thay sends for example u+1f600 that is called a grinning face. When I try to store this in the MySQL Text field I get Server does not support 4-byte encoded so a fast solution is to remove all these special chars from the string.
The question is how? I know about the u+1f600 but I suspect that there could be more of them.
Consider switching to MySQL utf8mb4 encoding... https://mathiasbynens.be/notes/mysql-utf8mb4

Password complexity condition [duplicate]

This question already has answers here:
Regular expression to enforce complex passwords, matching 3 out of 4 rules
(4 answers)
Closed 8 years ago.
I have following requirement in my application. I need to maintain password complexity in my application as mention below.
password length is minimum 8 characters, a capital letter, a special character apart from # and numeric values which are not in sequence
Can anyone help me in getting regular expression for the above criteira or else C# code is also helpful for me.
Let me suggest a different approach: Instead of creating a fancy regular expression that confuses everyone reading it (including you, since you cannot come up with one on your own), just encode the logic in a few simple C# statements:
if (mypassword.Length < 8)
myerror = "The password must have a minimum length of 8 characters.";
else if (!Regex.IsMatch(mypassword, "[A-Z]"))
myerror = "The password must contain at least one capital letter.";
...

Regex for matching US phone number with or without area code [duplicate]

This question already has answers here:
How to validate phone numbers using regex
(43 answers)
Closed 9 years ago.
My question was marked as a duplicate so I've made a couple edits. As I said, I was able to find many similar questions when I searched but none were quite what I needed. I am not validating a string where the only thing present will be the phone number (this seems to be what most of the other questions are addressing). Rather, I am attempting to pull out all phone numbers (which will then be manually checked by the user) from a larger block of text. The problem I am having is that my regular expression is matching zip codes with extensions (ex: 45202-4787), and I am not sure how to alter my regex to avoid that. If this truly is a duplicate question then I apologize for not being able to find the existing one that deals with my issue.
My specifications for phone number format are:
1) -, ., and space as delimiters (and in any combination)
2) area code may appear with or without parentheses
A few examples:
(xxx) xxx-xxxx
(xxx) xxx.xxxx
xxx-xxx-xxxx
xxx xxx-xxxx
xxxxxxxxxxx
I am using Anirudh's regex from the comments:
(\(?\d{3}\)?)?[. -]?\d{3}[. -]?\d{4}
Again, my problem is that this regex matches zip codes with extensions (ex: 45202-4787).
I would be grateful for any help, as I'm very new to using regular expressions. Thanks!
This should do it:
^(\([0-9]{3}\)|[0-9]{3})[ -\.]?[0-9]{3}[ -\.]?[0-9]{4}$

Categories