Still celebrating National IT Professionals Day with 3 months of free Premium Membership. Use Code ITDAY17

x
?
Solved

Regular expression to allow alpha numeric plus some other characters.

Posted on 2016-09-19
12
Medium Priority
?
71 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 52

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 52

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
Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

 

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 52

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 52

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 64

Accepted Solution

by:
Fernando Soto earned 2000 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 52

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 64

Expert Comment

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

Featured Post

Technology Partners: We Want Your Opinion!

We value your feedback.

Take our survey and automatically be enter to win anyone of the following:
Yeti Cooler, Amazon eGift Card, and Movie eGift Card!

Question has a verified solution.

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

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.…
Calculating holidays and working days is a function that is often needed yet it is not one found within the Framework. This article presents one approach to building a working-day calculator for use in .NET.
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

715 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