I have to validate a number enter by user with separted by comma only I am making insertion sort in javascript not jquery etc..
like 1,8,9,5,2,7
5,5,7,9,9
-8,5,-7,6,8
the limit of number will be 5.
IMHO. this is a fairly basics programming problem that someone with your experience should be a able to solve. Please share your JavaScript code. Explain the expected results and the actual results.
I know It is very basic, I have done it in c# without validation, now i want to do insertion sort in javascript with html, I
I need to validate only by javascript and have to show by alert that there would be only number with separation of comma.
<html>
<head>
<script>
function Render(){
var myName=frmMain.txtname.value;
alert(myName); // here I need validation if number is not given by user with separated by comma, that could be an array separated by comma.
}
</script>
</head>
<body>
<form name="frmMain">
<label> Enter any five numbers by separating comma </label>
<input type="text" name="txtname" />
<input type="submit" value ="Submit" onclick="Render()"/>
</form>
</body>
</html>
Not clear about your requirement, do you mean you want to validate numbers separated by comma and its max number count is five?
If so , you could try regex of javascript.
var regex = /^(-?\d+\,){0,4}(-?\d+)$/; //number after which there is a comma appears 0-4 times, number without comma appears for one time, - is allowed regex.test("11,-12,9")
You could also use string.split to split the string with comma to see whether the returned array's length smaller then 5, and validate every element of the array to see whether it is a number.
Best regards,
Ackerly Xu
MSDN Community Support
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.
Member
104 Points
265 Posts
validation for numbers with comma only
Feb 24, 2019 02:03 PM|Khan_1|LINK
I have to validate a number enter by user with separted by comma only I am making insertion sort in javascript not jquery etc..
like 1,8,9,5,2,7
5,5,7,9,9
-8,5,-7,6,8
the limit of number will be 5.
All-Star
53131 Points
23678 Posts
Re: validation for numbers with comma only
Feb 24, 2019 02:53 PM|mgebhard|LINK
IMHO. this is a fairly basics programming problem that someone with your experience should be a able to solve. Please share your JavaScript code. Explain the expected results and the actual results.
Member
104 Points
265 Posts
Re: validation for numbers with comma only
Feb 24, 2019 06:10 PM|Khan_1|LINK
I know It is very basic, I have done it in c# without validation, now i want to do insertion sort in javascript with html, I
I need to validate only by javascript and have to show by alert that there would be only number with separation of comma.
All-Star
53131 Points
23678 Posts
Re: validation for numbers with comma only
Feb 24, 2019 06:56 PM|mgebhard|LINK
No valuation logic posted! Share your code and explain the expected results and actual results.
Contributor
3500 Points
1300 Posts
Re: validation for numbers with comma only
Feb 25, 2019 04:29 AM|Ackerly Xu|LINK
Hi Khan_1,
Not clear about your requirement, do you mean you want to validate numbers separated by comma and its max number count is five?
If so , you could try regex of javascript.
You could also use string.split to split the string with comma to see whether the returned array's length smaller then 5, and validate every element of the array to see whether it is a number.
Best regards,
Ackerly Xu
Please remember to click "Mark as Answer" the responses that resolved your issue.
If you have any compliments or complaints to MSDN Support, feel free to contact MSDNFSF@microsoft.com.