Solved

Regular expression to allow alpha numeric plus some other characters.

Posted on 2016-09-19
12
60 Views
Last Modified: 2016-09-19
Please can I have a regular expression for C# to allow alpha numeric characters plus the following:
( ) & = . / , : ' + -

I tried this which seems to work unless the forbidden character is last.  I based myself on this site.
https://www.owasp.org/index.php/OWASP_Validation_Regex_Repository

Function ValidateRtrDescription(ByVal Description As String) As Boolean

        Dim emailRegex As New System.Text.RegularExpressions.Regex("[^[a-zA-Z0-9 ()&=./,:'+-]$")  '%[A-Za-z,~:/;#-.]%'
        Dim emailMatch As System.Text.RegularExpressions.Match = emailRegex.Match(Description)
        Return emailMatch.Success
    End Function
0
Comment
Question by:AlHal2
[X]
Welcome to Experts Exchange

Add your voice to the tech community where 5M+ people just like you are talking about what matters.

  • Help others & share knowledge
  • Earn cash & points
  • Learn & ask questions
  • 5
  • 5
  • 2
12 Comments
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41804546
HI,

pls try
       Dim emailRegex As New System.Text.RegularExpressions.Regex("[^[a-zA-Z0-9\(\)&=\./,:'\+-]$")  '%[A-Za-z,~:/;#-.]%'

Open in new window

REgards
0
 

Author Comment

by:AlHal2
ID: 41804563
It let this through.  ~ is not valid.

Hong Kong Stock Exchange Equities+~
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41804600
I've based my answer with line 2

then try

       Dim emailRegex As New System.Text.RegularExpressions.Regex("[^[a-zA-Z0-9\(\)&=\./,;:'\~#-]$")  '%[A-Za-z,~:/;#-.]%'

Open in new window

0
Online Training Solution

Drastically shorten your training time with WalkMe's advanced online training solution that Guides your trainees to action. Forget about retraining and skyrocket knowledge retention rates.

 

Author Comment

by:AlHal2
ID: 41804626
I'm using this expression which you gave me.  It's rejecting these which should be accepted.

Hong Kong Stock Exchange Equities+:
Hong Kong Stock Exchange Equities
HongKongStockExchangeEquities+;

Dim emailRegex As New System.Text.RegularExpressions.Regex("[^[a-zA-Z0-9\(\)&=\./,;:'\~#-]$")  '%[A-Za-z,~:/;#-.]%'

Open in new window

0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41804636
Sorry I've deleted the space and the plus
       Dim emailRegex As New System.Text.RegularExpressions.Regex("[^[a-zA-Z0-9\(\)&=\s\./,;:'#~\+-]$")  '%[A-Za-z,~:/;#-.]%'

Open in new window

0
 

Author Comment

by:AlHal2
ID: 41804786
It's rejecting this.

Hong Kong Stock Exchange Equities
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41804801
let's try
       Dim emailRegex As New System.Text.RegularExpressions.Regex("^[a-zA-Z0-9\(\)&=\s\./,;:'#~\+-]+$")  '%[A-Za-z,~:/;#-.]%'

Open in new window

0
 
LVL 63

Accepted Solution

by:
Fernando Soto earned 500 total points
ID: 41804838
Hi AlHal2;

Try this pattern to see if it helps.
Dim emailRegex As New System.Text.RegularExpressions.Regex("^[a-zA-Z0-9 \(\)&=\./,:;'\+-]+$")

Open in new window

0
 

Author Comment

by:AlHal2
ID: 41804854
It accepted
Hong Kong Stock Exchange Equities+~
even though ~ is forbidden.
0
 
LVL 51

Expert Comment

by:Rgonzo1971
ID: 41804859
then try
       Dim emailRegex As New System.Text.RegularExpressions.Regex("^[a-zA-Z0-9\(\)&=\s\./,;:'#\+-]+$")

Open in new window

0
 

Author Closing Comment

by:AlHal2
ID: 41804861
Please ignore what I said before.  This works so far.

Thanks,
Alistair
0
 
LVL 63

Expert Comment

by:Fernando Soto
ID: 41805298
Not a problem Alistair, glad to help.
0

Featured Post

Salesforce Has Never Been Easier

Improve and reinforce salesforce training & adoption using WalkMe's digital adoption platform. Start saving on costly employee training by creating fast intuitive Walk-Thrus for Salesforce. Claim your Free Account Now

Question has a verified solution.

If you are experiencing a similar issue, please ask a related question

Suggested Solutions

Title # Comments Views Activity
Move inline javascript functions to external .js file in asp.net 12 57
Windows Universal App 22 63
asp.net mvc5 6 34
Pdf not loading 2 40
User art_snob (http://www.experts-exchange.com/M_6114203.html) encountered strange behavior of Android Web browser on his Mobile Web site. It took a while to find the true cause. It happens so, that the Android Web browser (at least up to OS ver. 2.…
This article aims to explain the working of CircularLogArchiver. This tool was designed to solve the buildup of log file in cases where systems do not support circular logging or where circular logging is not enabled
Learn how to match and substitute tagged data using PHP regular expressions. Demonstrated on Windows 7, but also applies to other operating systems. Demonstrated technique applies to PHP (all versions) and Firefox, but very similar techniques will w…
Explain concepts important to validation of email addresses with regular expressions. Applies to most languages/tools that uses regular expressions. Consider email address RFCs: Look at HTML5 form input element (with type=email) regex pattern: T…
Suggested Courses

738 members asked questions and received personalized solutions in the past 7 days.

Join the community of 500,000 technology professionals and ask your questions.

Join & Ask a Question