My check() method is not working


I use check() method to filter the character inputs in my form fields. to check if only string is inputted in the name text field.
i already include the check package using meteor add check in command prompt. and also use import { check } from 'meteor/check'; to my Meteor method file. but still its not working. client can still input any character to the text field and received by the database

here is the codes:

		'submit form': function(event){
			var playerNameVar =;
			var playerScore =;
			if(playerNameVar!=""){'createPlayer', playerNameVar, playerScore); = ""; = "";


import {Monggo} from 'meteor/mongo';
import { check } from 'meteor/check';
export const PlayersList = new Mongo.Collection('players');

	'createPlayer': function(playerNameVar,playerScore){
		check(playerNameVar, String);
		var currentUserId = Meteor.userId();
			check(playerNameVar, String);
				name: playerNameVar,
				score: playerScore ? playerScore : 0,
				createdBy: currentUserId

Thanks in advance


HTML input data is always treated as a string. Even if you enter 1234, that’s actually stored as '1234'.

BTW, you have a typo here: import {Monggo} from 'meteor/mongo'; - but that’s nothing to do with your issue.


i see sir! thank you for finding the problem and the typo. what is th best solution here? what i have in mind is to use Number() method for checking the Numbers… but for strings. i have no idea


You should consider check as a tool to close an attack vector, rather than as a tool to validate input data (although it can be used for that). So, first use check to validate that the player name is a string (if it’s not a string, it may mean someone is trying to attack your server code).

If it is a string, then validate the content accordingly. For example, if it’s from a numeric field on the form, then first ensure only numeric characters are present, then use parseInt or the + hack to convert the string to number. Then ensure the number is in the expected range.


thank you very much for the enlightenment! I will apply that to my work. I’ll comment again after i resolve the issue