Regular expression

Posted by Sibin.rhythm under ASP.NET on 8/29/2009 | Views : 996 | Status : [Member] | Replies : 4
Please give me a regular expression which satisfy Charrecters and numbers
<br><!,>,<dfdsdf,. these symbols never accept
valid ------> anu , anish, anu897
invalid --------> <anu ,anu< ,an<dd,<and>

can anybody help me??????




Responses

Posted by: Lakhangarg on: 8/30/2009 [Member] [Moderator] Silver

Up
0
Down
Hi Sibin --

i think you need to write a javascript function for this.

Save the values in an array that you don't want to include then compare you value with this set of values.

Thanks & Regards
Lakhan Pal Garg
http://lakhangarg.blogspot.com/


Sibin.rhythm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Prashant_p2p on: 9/1/2009 [Member] Starter

Up
0
Down
var re=/([a-zA-Z0-9]+,)+/;

use this regular expression .

Regards,
prashant,
cgg,
hyderabad

Sibin.rhythm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/3/2009 [Member] [MVP] Bronze

Up
0
Down
Hey

You can do this with the following code:


using System.Text.RegularExpressions;

public bool TestForLettersAndNumbers(string input)
{
Regex rx = new Regex(@"^([A-Za-z0-9]+)$");

return rx.IsMatch(input);
}


You would use it like:

bool HasPassed = TestForLettersAndNumbers("somevalidcode");


Dont forget that as per your requirements this method wont allow puntuation or spaces.

Sibin.rhythm, if this helps please login to Mark As Answer. | Alert Moderator

Posted by: Rtpharry on: 9/3/2009 [Member] [MVP] Bronze

Up
0
Down
FYI vb.net version would look like

Imports System.Text.RegularExpressions


Public Function TestForLettersAndNumbers(ByVal input As String) As Boolean
Dim rx As New Regex("^([A-Za-z0-9]+)$")
Return rx.IsMatch(input)
End Function


used like

Dim HasPassed As Boolean = TestForLettersAndNumbers("somevalidcode")


Sibin.rhythm, if this helps please login to Mark As Answer. | Alert Moderator

Login to post response