Regex to Validate GSTIN Number [duplicate] - c#

This question already has answers here:
Regular expression for GST Identification Number (GSTIN)
(14 answers)
Closed 5 years ago.
How to Validate GSTIN Number using regex.
eg.11ABCDE1234L1Z1
My current regex is:
^([a-zA-Z0-9_\.\-])+\#(([a-zA-Z0-9\-])+\.)+([a-zA-Z0-9]{2,4}‌​)+$

Last digit is check digit. There is not much clarity on the internet on its validation - based on some real GSTIN examples - its alphanumeric - 0-9A-Z
The correct regex is therefore -
^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$

This seems to be the most accepted Regex for GSTIN Number.
/^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[1-9A-Z]{1}Z[0-9A-Z]{1}$/

Based on the requirements in the comment section, this is what I came up with.
([01]\d|[2][0-79]|[3][0-7])[A-Z]{5}\d{4}[A-Z]{1}\d[A-Z]{1}\d

how about this one?
\d{2}[A-Z]{5}\d{4}L\dZ\d

System.Text.RegularExpressions.Regex rPan =
new System.Text.RegularExpressions.Regex("^[0-9]{2}[A-Z]{5}[0-9]{4}[A-Z]{1}[0-9]{1}[Z]{1}[0-9]{1}$");

Related

Custom Regex format for ######-## [duplicate]

This question already has an answer here:
Learning Regular Expressions [closed]
(1 answer)
Closed 5 months ago.
I am absolutely clueless when it comes to Regex strings. I am trying to create a custom validator on a model using [RegularExpression("myValidator")] How can I create a regex expression to validate the following formats
######-##
######-#
where # is a number. Could someone help me out?
Thanks!
\d means digit.
{N} means previous symbol repeated N times
so, basically you want:
\d{6}-\d{2}
which would match 6 digits, a dash, and 2 more digits.
You can also do:
\d{6}-\d{1,2}
which would match 6 digits, a dash, and then 1 or 2 more digits, and therefore work for either format you described.

Check if a string only contains the characters > or < or - [duplicate]

This question already has answers here:
.NET Regex Error: [x-y] range in reverse order
(3 answers)
How to match hyphens with Regular Expression?
(6 answers)
Closed 4 years ago.
What I need is to check if a string only contains the characters > or < or -.
So I thought using a RegEx for this, and I found an SO question with the exact same problem, and it has an answer (not the accepted one but the answer with regex)
This is the SO question : String contains only a given set of characters
So I modified the expression in this question to fit my needs like this :
static readonly Regex Validator = new Regex(#"^[><- ]+$");
and I call it like this ;
Validator.IsMatch(testValue)
But it's throwing the error
x-y range in reverse order
There are lots of question on SO about this error but I cant find or understand the answer I need.
So what am I doing wrong with this RegEx?
^[-<>]+$ "-" must come first in C# regex
Escape - within character groups. ([0-9] means "zero to nine" and not "zero, dash or nine")

How to match 2 substrings in responce with regex in c# [duplicate]

This question already has answers here:
Returning only part of match from Regular Expression
(4 answers)
Closed 4 years ago.
I have a responce string
"c=2020&action=approvecomment&_wpnonce=7508ac918a' data-wp-lists='dim:the-comment-list:comment-2020:unapproved:e7e7d3:e7e7d3:new=approved"
Im trying to extract 2020 and 7508ac918a. I dont understand how I must use regex with substrings in C#, simple regex like
c=(\d+)&action=approvecomment&_wpnonce=(.*?)' .+new=approved.
In Regex, you can create match groups
They look like this (?.+?)
So your _wpconce part could become something like this (?.*?)
Then you can grab each group individually for example
Match result = myRegex.Match(someString);
soneOtherString = result.Groups["GROUPNAME"].Value;
I use Regex101 to build and test my regex. (Whoever made that site deserves a crown with shinny stones on it!! :)
https://regex101.com/
Hope this helps

Regex Pattern to check only letters [duplicate]

This question already has answers here:
C# Regex to allow only alpha numeric
(6 answers)
Closed 5 years ago.
I need to check whether string is only contain letters but not numbers or special characters.I used below regex pattern,
String validText = "^[a-zA-Z-]+$";
its work fine for 'Leo#' but if it is like 'Leo#1' its not working properly.
Anyone have idea ?
I prefer you can use LinQ (input is your test string)
bool result = input.All(Char.IsLetter);
Else as Gordon Posted the right Regex,
^[a-zA-z]+$
You can try using this regex
/^[A-Za-z]+$/
This will match only letters in your string ..

Validate an integer with a specific 0-65536 range in Regex C# [duplicate]

This question already has answers here:
How to match numbers between X and Y with regexp?
(7 answers)
Closed 6 years ago.
I am new to learning Regex and I have tried almost everything myself and from the internet to find a Regex that accepts values from 0 to 65536 and yes I want to do it by Regex only. The Closest I got was 69999.
Here it is:
^(?:[0-5]?[0-9]{1,4}|6[0-4][0-9]{3}|65[0-4][0-9]{2}|655[0-2][0-9]|6553[0-6])$
See demo
Split it into multiple ranges: 0-9, 10-9999, 10000-59999, 60000-64999, 65000-65499, 65500-65529, 65530-65536
^(?:\d|[1-9]\d{1,3}|[1-5]\d{4}|6[0-4]\d{3}|65[0-4]\d{2}|655[0-2]\d|6553[0-6])$

Categories

Resources