C# Tutorials and offshore development in India
    Tutorials   Resources   Forum   Reviews   Communities   Interview   Jobs   Projects   Training   Your Ad Here    
Silverlight Games | Mentor | Code Converter | Articles | Code Factory | Computer Jokes | Members | Peer Appraisal | IT Companies | Bookmarks | Polls | Revenue Sharing | Lobby | Gift Shop |


Prizes & Awards
My Profile



Active Members
TodayLast 7 Days more...






Resources » Articles » .NET Framework »

Regular Expressions


Posted Date: 11 Feb 2009    Resource Type: Articles    Category: .NET Framework
Author: ShankarMember Level: Diamond    
Rating: 1 out of 5Points: 20



This article will gives u the certain regular expressions that will be used normally in all the applications.


Numeric Validation
----

1. ‘\d+’ – Only numbers (0-9) can be entered in the field.
2. ‘^[0-9]*$’ – Only numbers (0-9) can be entered in the field.
3. ‘^9[0-9]*$ - Only numbers (0-9) can be entered in the field.The number will always start with 9.
4. ‘^\d{1,4}$’ – Numbers may be of length starting from single digit to fourdigits.
5. [0-9]{5} – Only numbers are allowed.The maxlength for the number will be five digits.
6. ‘[+][0-9]{1,4}[-][0-9]{1,6}[-][0-9]{1,15}’ – Numbers will be in the format of +44-20-76297988
+44(Maxlength will be from singledigit to fourdigits)-20(Maxlength will be from singledigit to sixdigits)-76297988(Maxlength will be from singledigit to fifteen digits)

Email Address Validation
----

Expression 1
----

‘[A-Za-z0-9!#$%&'*+/=?^_`{|}~-]+(?:\.[a-zA-Z0-9!#$%&'*+/=?^_`{|}~-]+)*@(?:[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?\.)+[a-zA-Z0-9](?:[a-zA-Z0-9-]*[a-zA-Z0-9])?’

Expression 2
-----

^([A-Za-z0-9_\-\.])+\@([A-Za-z0-9_\-\.])+\.([A-Za-z]{2,4})$


String Validation
----
1. ‘^[\w+\s]+$’ – Any characters with whitespace will be allowed

2. ‘^[\w,-,'.']+$’ – Characters and special characters like ‘–‘ and ‘.’ are allowed




Responses

Author: Devendra    04 Jul 2009Member Level: Gold   Points : 1
Dear,

Thanks for valuable help.
We can use it in future and you can make it more wide
like
Image Upload Control Validations (For File extensions)
Like for Photo u can use
/^(([a-zA-Z]:)|(\\{2}\w+)\$?)(\\(\w[\w].*))(.jpg|.JPG|.gif|.GIF|.png|.PNG|.bmp|.BMP)$/

And Many More


Feedbacks      
Popular Tags   What are tags ?   Search Tags  
Sign In to add tags.
Regular Expressions  .  Numeric validation  .  Number validation  .  Number  .  Email validation  .  Email  .  

Post Feedback


This is a strictly moderated forum. Only approved messages will appear in the site. Please use 'Spell Check' in Google toolbar before you submit.
You must Sign In to post a response.
Next Resource: Composition and Aggregation in UML
Previous Resource: Association and Generalization of UML
Return to Discussion Resource Index
Post New Resource
Category: .NET Framework


Post resources and earn money!
 
Related Resources



dotNet Slackers

About Us    Contact Us    Privacy Policy    Terms Of Use