PDA

View Full Version : Number Comma Validation



thekevin07
Mar 8th, 2007, 10:12 PM
HI

I have source code that detects if a variable has a comma or number in it code below. For some reason it wont allow the comma anyone know why?



if(validateAlpha(new_text) ==false)
{
alert('fail');
return;
}

function validateAlpha(new_text)
{
var NumRegxp = /^([0-9,]+)$/;
if (NumRegxp.test(new_text) == true)
{
return true;
}
else
{
return false;
}
}

chump2877
Mar 9th, 2007, 02:07 AM
your regex is fine...the following code works for me:


<script type="text/javascript">
function validateAlpha(obj)
{
var new_text = obj.value;
var NumRegxp = /^([0-9,]+)$/;
if (!NumRegxp.test(new_text))
{
alert('error');
return false;
}
else
{
alert('ok');
}
}
</script>


<input type="text" onblur="validateAlpha(this);" />