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

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

Related

Enter number in one textbox and get word as output in another textbox

This Question was asked in interview but i was unable to answer it
please any one can tell me how to do this ?
i have two textboxs txtInput and txtOutput
When user clicks the btnSubmit, he should get the number written in txtInput in words in txtOutput. Eg. if user enters 100 in txtInput, he should get hundred in txtOutput
Prumably this is JS. If it is the you can setup an event listener on the submit button and disable the default behavior. Pass the input value to a function that builds the number string and update the dom element for the output textbox with that return result.
If you're using a round trip to the server for the calculation then just ignore all the dom stuff and return the page with the appropriate values set.
If you're using a front end framework then this gets easier but more specific to the framework.
thanks ..found solution here
.NET convert number to string representation (1 to one, 2 to two, etc...)

Currency textbox in ASP

I tried the Masked Edit from the AJAX Toolkit Extender but it doesn't do what I need to do. Its too clumsy and it also breaks a small script I run that calculates the textboxes automatically. One of the textboxes (total) is data bound and there's a second one where the user inputs an amount and I need to force it so its in currency format (only two decimals, $ sign). I tried with a range validator but I would then also limit the amounts to whatever number I input.
You could use RegularExpression validator, here is a regex from regexlib.com for currency validation.
^\$?([0-9]{1,3},([0-9]{3},)*[0-9]{3}|[0-9]+)(.[0-9][0-9])?$

Store ID and Text

How can I set some text to a label but also store its ID. For instance I'm taking an ID/text value pair and painting the text in a label but I need to store the ID somewhere to be able to retrieve both that text value and ID later on for some more logic in the page.
I don't think you can store an ID in a label...which is what I'm using. I can append html() to the label using jquery's html() function but then I do not know if this is a good html control to be using as I can't store the ID anywhere.
It is probably obvious what my choices are but honestly I've never come across this issue before. I thought I could use an asp.net literal but I don't think that's gonna help me either with storing the ID.
When I'm required to do this, e.g. inside a Repeater, I solved this storing the ID inside an additional hidden field.
This enabled me to later retrieve the ID back, e.g. after a postback or through JavaScript in the client.
See this MSDN page for a description of the Value property as well as an example that deals with JavaScript and postback.
if you are using jQuery,you can use jQuery.data(); for this. And if you are using HTML5 , you can use client side storage.
You have several options.
Convert the value to a string and store the value in a HiddenField.
Store the value in the Session.
Store the value in the ViewState.
You have 3 options to store your ID:
Session Variable
ViewState
HiddenField

email id validation in asp.net?

In my web application i have a textbox with multiline property is true, when ever i type emailids separating with comma how can i validate multiple emailid in this situation.
like: sasidhar#yahoo.com,surya#gmail.com in a textbox how can i validate please help me
Here's the general idea:
Split the values and store it into an array, then validate it using (I recommend this): http://www.coveryourasp.com/ShowSource.asp?page=ValidateEmail

What is the purpose and proper use of a textfields max-length property?

What is the purpose and proper use of the max-length property on text fields?
The application I'm working on limits numeric fields to 6 characters... which doesn't work very well for entering millions of dollars... which is why I'm "fixing" it.
MaxLength Sets or receives the maximum number of characters that a user can enter into a Text control.
EDIT: You do this to prevent having to process something that you know is guaranteed to be wrong.
If you have a text field in your database that is set to 10 characters and the user enters 11 and you don't handle it properly, you cause an exception.
So, just set the maxlength to 10 and you won't have any problems like this.
The Maximum length attribute of a text field and/or textarea effectively limits the user from entering data that is outside the bounds and constraints you have set for your database.
You can use this to make sure users enter in valid SKU numbers, blog titles, ISBN numbers, etc. It is a rudimentary form of data validation.
This doesn't always need to be tied to data validation though.
You could want to limit the length of a string that a user has entered for aesthetic reasons when displaying that data on a page in another location.

Resources