Hi all i would like to have a regex that should allow numeric values along with .
also i will have a maximum length for text box as 10 if i enter only numeric it should count if i enter dot it should not count as an input.
Also i wrote a javascript to convert the entered number to US format so my text box will always have its initial value as $.
Example :
If user enters 1234567890 as per my script it will convert as $1234,567,890.00 which works fine but user can enter some thing like 1.23 so that it will convert to $1.23 so i need a regex such that first character should be $ and dot is allowed in between the numbers and only numeric values should count as length
Loading
ChaitanyaPosted Sep 28, 2011, 3:52 AM
Rakesh JhaPosted Sep 28, 2011, 2:59 AM
function SplChar(evt)
{
evt = (evt) ? evt : window.event;
var charCode = (evt.charCode) ? evt.charCode : ((evt.which) ? evt.which : evt.keyCode);
if ((charCode >= 48 && charCode <= 57) || charCode == 36 || charCode == 46 || charCode == 44)
return true;
else
return false;
}
function btnClick() {
var objTextBox = document.getElementById("textBox1");
alert((new RegExp(/^[\$]{1}[\.]?[\,]?\d{1,10}/gi)).test(objTextBox.value));
if (objTextBox.value.replace(/[\$\.\,]/gi, "").length > 10)
alert("length exceeded");
}
you can implement it for server side also
ChaitanyaPosted Sep 28, 2011, 2:00 AM
Hemant KumarPosted Sep 28, 2011, 1:58 AM
try this: ^[0-9]+$
for more help refer this link
http://rjdudley.com/blog/index.php/2005/05/allowing-only-numbers-in-asp-net-textboxes-use-regular-expression-validator/