Skip to content

Conversation

@xiaoxustudio
Copy link
Member

@xiaoxustudio xiaoxustudio commented Jan 3, 2026

getUserInput添加正则验证功能参数

新增参数:

  • rule:校验规则,这里的输入将会被视作为一个正则表达式
  • ruleFlag:标识,如:g,i
  • ruleText:校验不通过时提示的文本,可用$0获取输入的文本

写法示例:

getUserInput:name -title=如何称呼你 -buttonText=确认 -rule=^.{1,2}$ -ruleText=$0不符合1-2个字符;
WebGAL:很高兴遇见你,{name}!

当正则出现错误时,会跳过验证,并在控制台打印信息
image

close #769 #782

@gemini-code-assist
Copy link

Summary of Changes

Hello @xiaoxustudio, I'm Gemini Code Assist1! I'm currently reviewing this pull request and will post my feedback shortly. In the meantime, here's a summary to help you and other reviewers quickly get up to speed!

此拉取请求旨在通过为 getUserInput 函数引入强大的正则表达式验证功能,显著提升用户输入的质量和可靠性。这一改进使得应用程序能够更灵活地处理用户数据,并在输入不符合预期格式时提供即时反馈,从而优化了用户体验并增强了数据完整性。

Highlights

  • getUserInput 功能增强: 为 getUserInput 函数添加了正则表达式验证功能,允许开发者为用户输入设置校验规则。
  • 新增参数: 引入了 rule (校验规则), ruleFlag (正则表达式标识,如 g, i), 和 ruleText (校验失败时的提示文本,支持 $0 替换为用户输入) 三个新参数。
  • 错误处理: 当提供的正则表达式无效时,系统会跳过验证并打印警告日志,确保程序的健壮性。

🧠 New Feature in Public Preview: You can now enable Memory to help Gemini Code Assist learn from your team's feedback. This makes future code reviews more consistent and personalized to your project's style. Click here to enable Memory in your admin console.

Using Gemini Code Assist

The full guide for Gemini Code Assist can be found on our documentation page, here are some quick tips.

Invoking Gemini

You can request assistance from Gemini at any point by creating a comment using either /gemini <command> or @gemini-code-assist <command>. Below is a summary of the supported commands on the current page.

Feature Command Description
Code Review /gemini review Performs a code review for the current pull request in its current state.
Pull Request Summary /gemini summary Provides a summary of the current pull request in its current state.
Comment @gemini-code-assist Responds in comments when explicitly tagged, both in pull request comments and review comments.
Help /gemini help Displays a list of available commands.

Customization

To customize Gemini Code Assist for GitHub experience, repository maintainers can create a configuration file and/or provide a custom code review style guide (such as PEP-8 for Python) by creating and adding files to a .gemini/ folder in the base of the repository. Detailed instructions can be found here.

Limitations & Feedback

Gemini Code Assist may make mistakes. Please leave feedback on any instances where its feedback is incorrect or counter productive. You can react with 👍 and 👎 on @gemini-code-assist comments. If you're interested in giving your feedback about your experience with Gemini Code Assist for Github and other Google products, sign up here.

You can also get AI-powered code generation, chat, as well as code reviews directly in the IDE at no cost with the Gemini Code Assist IDE Extension.

Footnotes

  1. Review the Privacy Notices, Generative AI Prohibited Use Policy, Terms of Service, and learn how to configure Gemini Code Assist in GitHub here. Gemini can make mistakes, so double check it and use code with caution.

Copy link

@gemini-code-assist gemini-code-assist bot left a comment

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Code Review

这个 PR 为 getUserInput 添加了正则表达式验证功能,整体实现得不错。我发现了一个潜在的严重 bug,当 userInput 元素不存在时,代码会尝试访问 null 的属性导致程序崩溃。我已经提供了一个修复建议。另外,我还建议改进验证失败时的错误提示方式,以提升用户体验。请查看具体的评论。

if (rule) {
const reg = tryToRegex(rule, ruleFlag);
if (reg && !reg.test(userInput.value)) {
if (ruleText) alert(ruleText.replaceAll(/\$0/g, userInput.value));

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

medium

使用 alert() 会阻塞浏览器主线程,并且其样式是浏览器默认的,无法与游戏的 UI 风格统一,可能会给用户带来突兀的体验。建议考虑使用游戏内的 UI 组件来展示错误信息,例如在输入框下方显示一段红色的提示文字。这可能需要将此组件转换为一个有状态的组件来管理错误信息,但能显著提升用户体验。

Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

None yet

Projects

None yet

Development

Successfully merging this pull request may close these issues.

1 participant