javascribt for number

I build app for student, so when the student type mobile number and if he type alphabet. I want to appear a message that you can type only numbers with max of the numbers

what kind of the javascript I should write?
1 person has
this question
+1
Reply
  • In the Input field ‘type’ selection - select ‘tel’ and on the device - when compiled - under both IOS and Android- the number pad will appear forcing the user to type numbers from the number pad only .


    In terms of determining that the input is a fixed number of characters Appery(“yourcontrolname”).val().trim().length will give you that ... so you can compare it to A fixed number and do an alert( ‘ please enter 10 numbers’) , etc


    If you require formatting the phone number and this is going to be a web app and you have 10 or 13 digit phone number ... let me know ... I have JavaScript That you can use on value change to handle that situation.


    Best,


    Bruce
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Thank you so much

    I have this javascript

    if(Appery("srchCRN").val().length > 5)
    {
    alert("Please write the correct CRN");
    }
    how I can add the type if I want number or characters

    I have another question how I navigate page by using javascript
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. happy, confident, thankful, excited indifferent, undecided, unconcerned kidding, amused, unsure, silly sad, anxious, confused, frustrated

  • Noor,

    You need to 'attempt' to convert the string value that sits on the control - to a number - if it fails - you know it's of type string.

    So - for example - if the control has '1234456' on it - and you run the Javascript

    nValue = Number( Appery("srchCRN").val().trim() ) - you will get a number 123456 (type is 'numeric').

    If the value on the control is 'a123456' - you will get NaN (not a numeric) - if you want the affirmative (which will tell you if it is a number)....

    Javascript:

    if ( !isNan( Number( Appery("srchCRN").val().trim() ) ) ) {
    alert('Hey it is a number') ;
    } else
    {
    alert('Hey its a string');
    }

    Best,

    Bruce
  • (some HTML allowed)
    How does this make you feel?
    Add Image
    I'm

    e.g. sad, anxious, confused, frustrated kidding, amused, unsure, silly indifferent, undecided, unconcerned happy, confident, thankful, excited