סימן קכז סעיף ח
הַמִּתְעַנֶּה וּמְפַרְסֵם אֶת עַצְמוֹ לְהִתְפָּאֵר, הוּא נֶעֱנָשׁ עַל כָּךְ. אֲבָל אִם מַפְצִירִין בּוֹ לֶאֱכֹל, מֻתָּר לְגַלּוֹת שֶׁהוּא מִתְעַנֶּה (תקסה).
If someone fasts and publicizes the fact, bragging about it, he will be punished for it.9However, if you are asked if you are fasting, it would seem that you are permitted to acknowledge that you are. Mishnah Berurah, however, indicates that you should deny that you are fasting, unless you are asked to join someone in a meal, in which case you have no choice but to state you are fasting. On public fast days, however, you may say you are fasting in order to encourage others to do so. (Mishnah Berurah 565:14) But if people urge him to eat, he may let them know that he is fasting.
תנא דבי אליהו כל השונה הלכות בכל יום מובטח לו שהוא בן העולם הבא שנאמר הליכות עולם לו אל תקרי הליכות אלא הלכות (נדה ע"ג.)