Regex valid numbers with thousand separator - asp.net

I'm doing a validation in asp.net textbox, and the textbox only allows user to input number
i.e.
valid numbers:
1234
12.345
12,345,678.231
12,345,678
invalid numbers:
-1234
12.23.45.67
12,
12,34,56
12,345,6
I'm trying to use a regex to validate the user's input on client side with the below regex:
^(?=.+)(?:[1-9]\d*|0)?(?:\.\d+)?$
The problem is:
the above regex only consider below as valid:
1234
12.345
How to modify the above regex to check if the thousand separator being entered into the correct place or not?

this seems to work ^\d+(,\d{3})*(\.\d+)?$
Demo

Related

ASP.NET RegularExpressionValidator False Trigger

I'm validating a password that must be letters and digits with at least one digit and one upper case letter. I am using the following RegEx expression to do so:
(?=(^[a-zA-Z0-9]{6,16})$)(?=.*\d)(?=.*[A-Z])
Using this pattern, the password "Valid101" should be valid and it worked as expected at both A Better .NET Regular Expression Tester and REGEX TESTER. But, when I use it in my ASP.NET user control's RegularExpressionValidator it wrongly decides that password "Valid101" is not valid.
I'm hoping someone could suggest what might be wrong.
The pattern you have only consists of zero-width assertions, of lookaheads. They do not consume the text they match, so the match value after the regex matches is an empty string. The RegularExpressionValidator requires a full string match (i.e. the string matched should be the whole input string).
So, instead of (?=(^[a-zA-Z0-9]{6,16})$)(?=.*\d)(?=.*[A-Z]) use
^(?=.*\d)(?=.*[A-Z])[a-zA-Z0-9]{6,16}$
It will assure there is a digit and an uppercase ASCII letter in the string, and then will match (consume) 6 to 16 ASCII letters and digits.

ASP.NET: How to validate a number input and format it with thousand separator on fly?

On ASP.Net form, I have a couple input fields which only integer allowed and maximum is 8 digital. right after entering value to the textbox field, it will check the validation. after passing the validation, it will format it with thousand separator. all these happen on fly.
I use Regular Express to do the validation. for example: Regex="^-?\d+{0,8}$".
My question is: I can use this regex to check the input and format it with thousand separator, but when hit save button, it fails on validation(Page.IsValid) because the textbox value will show number with commas(,).
For example: since the field only takes integer,when user enter 20000, it pass regex check at first, but after it format with 20,000 it fails the validation.
So how can I make this work? Thanks.
You can try custom validator
How to: Validate with a Custom Function for ASP.NET Server Controls

asp.net regular expression validator for email or numeric

Is it possible use a regular expression validator for a textbox which accepts either user email or phone number (11 digits number which begins with 09) ?
so one regex is needed which accepts one of two cases, email or number.
For Email : "\w+([-+.']\w+)#\w+([-.]\w+).\w+([-.]\w+)*"
[0][9][0-9]

How to check if string contains numbers symbols

I have asp.net(c#) web form with html input text(first name) how i can check if string contains symbols, numbers, unicode text, space with c#
or its more easier with html?
I want to user entered only first name
This regular expression will only match on one or more ASCII characters:
^[A-Za-z]+$
You can use the above in either Javascript or .NET.

Need validation check which prompt as soon as user leave the control

We are developing an application where we have a Form to fill by users. Here is the scenario for some fields:
Name : Does not contain numbers like 123 but it can be alpha-numeric like mynangal123 but does not contain special characters
DOB : Does contain specific formats like mm.dd.yyyy or dd/mm/yyy or yyyy/mm/dd etc. doesn't contain alphabets
TAXID : Can be Numeric but not numbers like it can be "123" but not 123 also it can be T-125
Now, as per requirement we have to validate or prompt the user for specific input if he/she did not enter the specific entry. Like if in name User enter 123456 then there should be a messagebox to warn "please enter a valid name"
Restrictions : We have a option of Javascript but its not recommendable in most of scenario so, we need to create a custom validators or something else which will solve our problem.
Please provide some feasible solution for the issue.
Thanks in advance.
Use Custom Validators for this. They provide support for server side & client side validation.

Resources