views:

36

answers:

1

I was using isNaN function in a Facebook application, but it was not working. the code that i was using

<script type="text/javascript">
<!--
function postValid(form)
{
 var values=document.getElementById("phone").getValue();

 if(isNaN(values))
 {
    var myDialog = new Dialog(Dialog.DIALOG_POP);
    myDialog.showMessage('Almost Done!', 'Correct Mobile Numbers', button_confirm='Close');
 }
 else
 {
     var myDialog = new Dialog(Dialog.DIALOG_POP);
    myDialog.showMessage('Almost Done!', 'Please Enter Correct Mobile Numbers Please',    button_confirm='Close');
 }     
 }
  //-->
</script>

I have also used Regular expression but not working is there any alternative? or method by FBJS?

A: 

Yeah i got the Solution,

<script type="text/javascript">
<!--
function postValid(form)
{
 var params=form.serialize();
 var values=document.getElementById("phone").getValue();

 var numericExpression = /^[0-9]+$/;

 if(numericExpression.test(values))
 {
     if(values.length != 10)
     {
         var myDialog = new Dialog(Dialog.DIALOG_POP);
         myDialog.showMessage('Almost Done!', 'Enter 10 Digits',  button_confirm='Close');
         return false;
     }
     else
     {
         return true;
     }
 }
 else
 {
     var myDialog = new Dialog(Dialog.DIALOG_POP);
     myDialog.showMessage('Almost Done!', 'Please Enter Correct Mobile Number Please', button_confirm='Close');
     return false;
 }


}
 //-->
 </script>

we can use the Regular expression earlier i used the element.value.match(numericExpression) method which didnt work. if you have any other solution please post so that we can get a better solution.

Harish Kurup

related questions